CodeGenieApp / CodeGenieApp/serverless-express
express.static doesnt work with ALB endpoint
- Ngôn ngữ chính
- JavaScript
- Star
- 5.3k
- Fork
- 676
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
When using express.static, the files within the static path do not load and the endpoint (Application Load Balancer) returns a 502.
`
app.use(express.static(path.resolve("./public")));
`
I was trying to add a robots.txt to the static path and let express.static handle the routing and response, but when I try to load the page, it responds with a 502 Bad Gateway. I'm 100% sure the file exists and the static path is correct, I've logged it. Also, when I try to load an asset that isnt in the static path, like /robo.txt, it responds with a 404, so it's recognizing something.
I've looked into what can cause a 502 from ALB, some docs on AWS says that either the response is larger than 1MB or the lambda timed out, which neither of these things is the case in my situation. My speculation is maybe the response from express.static isnt being handled correctly for an ALB in "vendia/serverless-express"? Possibly a content-type header issue? I've run the app locally via serverless offline and as a stand alone express server, in both cases, the /robots.txt loads fine, which is why I think it might have something to do with how ALB is integrated with the library.
Anyways, I worked around this issue by just explicitly setting the robots.txt path and importing the txt file
```
import txt from "../../robots.txt";
app.use("/robots.txt", (req, res, next) => {
res.set("Content-Type", "text/plain");
res.send(txt);
});
```
Hướng dẫn đóng góp
Hướng nghiên cứu
Không có tệp mã nguồn hoặc bài kiểm thử nào được nêu. Hãy bắt đầu bằng cách tái hiện yêu cầu express.static đối với robots.txt thông qua ALB, sau đó so sánh với các trường hợp Express độc lập và serverless offline được mô tả trong issue. Hoàn tất khi các tệp tĩnh, bao gồm robots.txt, tải được thông qua ALB mà không có 502, trong khi các tệp không tồn tại vẫn trả về 404.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- aws, express, javascript
- Lĩnh vực
- api, backend, cloud
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 28/100