CodeGenieApp / CodeGenieApp/serverless-express

express.static doesnt work with ALB endpoint

Abierto
#563 11 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
5.3k
Forks
676
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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);
});
```

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

No se nombra ningún archivo fuente ni ninguna prueba. Empieza reproduciendo la solicitud de express.static para robots.txt a través del ALB y, después, compárala con los casos independientes de Express y serverless offline descritos en el issue. La tarea está terminada cuando los archivos estáticos, incluido robots.txt, se cargan a través del ALB sin un 502, mientras que los archivos que faltan siguen devolviendo 404.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
aws, express, javascript
Área
api, backend, cloud
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
28/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.