-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
express.static doesnt work with ALB endpoint #563
Comments
Try enabling the log level option to vendia/serverless doesn't interfere with express.static because it just waits for the response to be complete after forwarding to express, the problem may be in the |
Oh cool, didnt realize there was a debug option. Sure here are the logs, so it does look like it's getting the file
|
Yes, there is no problem on the express side and the One thing you can do now is run express with the option that works and try to see the logs, and compare the You should see some difference. If there is no difference then I don't know what's going on because when you see this log, the library is about to resolve and finish executing and return that json to AWS. |
so i logged what the response looks like when i explicitly set the /robos.txt (which correctly shows the robots.txt) this is what I get for
the only difference I see is that the "charset" on the content-type is "utf-8" vs "UTF-8" |
In that case, now you get this raw response and just return it in the lambda, erase all the code and leave it like this: export const index = () => {
return YOUR_JSON;
} And try with both options. If it works, well, we have a problem with the library. If it doesn't work, ALB doesn't like UTF-8 ahhahaah. |
ok, so i did what you suggested, interestingly enough, it works with both utf-8 and UTF-8
and
I confirmed in the browser inspector that the response headers reflects the code's response |
@ml27299 Also dude I really don't know what the problem you are having with the 502, if both answers are the same and the framework is resolving and returning, the only thing I could think of is |
Haha, I hate that award. Ya, issue doesnt really make sense to me either, everything seems to be setup correct. No, I didnt mess with
Thats my confg - luckily I dont serve compiled js assets via a static public path within the app, so I have very limited number of files I'd put there, robots.txt being it for now. Anyways, thx for guiding me thru this weird issue |
@ml27299 It looks like the handler is fine, well let's keep this issue open and if we see another one with this issue we can try to dig deeper to find the root cause of this bug. |
I met a very similar issue and in my case it was a type of content-length header. |
yep, that worked! Idk if it'd be better for vendia/serverless-express to stringify all the headers by default or allow a custom function to be passed in to edit the headers, but at the very least mentioning it in the docs. wrapper
|
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
The text was updated successfully, but these errors were encountered: