我已经通过Claudia JS部署了一个非常基本的Express应用程序 . 它运行良好,但任何链接或重定向都不会保持API网关阶段,因此不起作用 .
例如,我在http://example.execute-api.eu-west-2.amazonaws.com/production部署了应用程序 - 在本地运行时相当于http://localhost:3000 . 如果该页面上的链接 <a href="/test">
在本地转到http://localhost:3000/test,但是通过api网关它会转到http://example.execute-api.eu-west-2.amazonaws.com/test - 丢失URL的/ production部分,因此无法正常工作 .
有没有办法让Express知道所有路线都需要以/ production开头?
替代解决方案是使用自定义域,但这似乎很麻烦,解决看起来应该只是一点配置 .
1 回答
你可以使用这样的东西来构建基本URL;
https://${req.apiGateway.event.headers.Host}/${req.apiGateway.event.requestContext.stage}