[英]Cant get path: /{proxy+} to work (serverless-offline)
Excuse me if im misunderstanding how this should work, im fairly new to the serverless world.如果我误解了这应该如何工作,请原谅我,我对无服务器世界相当陌生。
I want to avoid having to explicity list all of my routes in my serverless.yml
file so have used the catch all {proxy+}
.我想避免在serverless.yml
文件中明确列出我的所有路由,因此使用了 catch all {proxy+}
。
When i run sls offline start
i see one route listed 👇🏼当我sls offline start
运行sls offline start
我看到列出了一条路线👇🏼
ANY | http://localhost:3000/dev/{proxy+}
However, when i try to access for example localhost:3000/dev/test-one
i see the following error Cannot GET /%7Bproxy+%7D
instead of my expected response.但是,当我尝试访问例如localhost:3000/dev/test-one
我看到以下错误Cannot GET /%7Bproxy+%7D
而不是我预期的响应。
Am i misunderstanding how to use this?我误解了如何使用它吗?
ps - this works when i explicity list my routes in my yml
file, but would like to avoid this if poss. ps - 当我在我的yml
文件中明确列出我的路线时,这有效,但如果可能的话,我想避免这种情况。
serverless.yml
service: simply-serverless-web
provider:
name: aws
plugins:
- serverless-offline
- serverless-express
functions:
app:
handler: app.handler
events:
- http:
path: /{proxy+}
method: ANY
cors: any
app.js
const express = require('serverless-express/express')
const handler = require('serverless-express/handler')
const app = express()
app.all('/test-one', require('./test-one'))
app.all('/test-two', require('./test-two'))
app.all('/test-three', require('./test-three'))
exports.handler = handler(app)
The problem is the stage dev
that your are using in the url.问题是您在 url 中使用的 stage dev
。 I dont think its correct for serverless-offline
environments.我认为它不适合serverless-offline
环境。
It should be (without dev
)它应该是(没有dev
)
ANY | http://localhost:3000/{proxy+}
hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.