CodeGenieApp / CodeGenieApp/serverless-express
express.static doesnt work with ALB endpoint
- 主要言語
- JavaScript
- スター
- 5.3k
- フォーク
- 676
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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);
});
```
コントリビューションガイド
調査の方向性
ソースファイルもテストも指定されていません。まず ALB 経由で express.static の robots.txt リクエストを再現し、その後、issue に記載されている standalone Express と serverless offline のケースと比較してください。静的ファイル(robots.txt を含む)が ALB 経由で 502 なしに読み込まれ、存在しないファイルは引き続き 404 を返せば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- aws, express, javascript
- 領域
- api, backend, cloud
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 28/100