首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >aws-serverless-express with serverless-离线阶段中断路由

aws-serverless-express with serverless-离线阶段中断路由
EN

Stack Overflow用户
提问于 2020-01-05 00:51:50
回答 1查看 506关注 0票数 2

我正在使用无服务器软件包:- aws- serverless -express - serverless-offline

当我运行sls offline

我让所有东西都正常运行,但我得到的路径是:

代码语言:javascript
运行
复制
ANY | http://localhost:3001/dev/
ANY | http://localhost:3001/dev/{proxy+}

serverless.yaml是

代码语言:javascript
运行
复制
functions:
  app:
    handler: src/lambda.handler
    events:
      - http:
          path: /
          method: ANY
          cors: true
      - http:
          path: /{proxy+}
          method: ANY
          cors: true

我知道我有“阶段”环境,我可以设置更改,但我的快递路线正在寻找它:

代码语言:javascript
运行
复制
//this wont work
app.get('/r', (req, res) => {
  res.send('ready');
})

//this will work
app.get('/dev/r', (req, res) => {
  res.send('ready');
})

但在生产中,或者如果我使用任何其他“阶段”,我的路线将无法工作,如果我不在它们前面加上阶段。

有什么想法吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-16 01:14:33

根据文档:

代码语言:javascript
运行
复制
sls offline --noPrependStageInUrl

应该可以为你工作

或通过配置:

代码语言:javascript
运行
复制
custom:
    serverless-offline:
        noPrependStageInUrl: true

Available Cli options:

代码语言:javascript
运行
复制
--apiKey                    Defines the API key value to be used for endpoints marked as private Defaults to a random hash.
--corsAllowHeaders          Used as default Access-Control-Allow-Headers header value for responses. Delimit multiple values with commas. Default: 'accept,content-type,x-api-key'
--corsAllowOrigin           Used as default Access-Control-Allow-Origin header value for responses. Delimit multiple values with commas. Default: '*'
--corsDisallowCredentials   When provided, the default Access-Control-Allow-Credentials header value will be passed as 'false'. Default: true
--corsExposedHeaders        Used as additional Access-Control-Exposed-Headers header value for responses. Delimit multiple values with commas. Default: 'WWW-Authenticate,Server-Authorization'
--disableCookieValidation   Used to disable cookie-validation on hapi.js-server
--enforceSecureCookies      Enforce secure cookies
--hideStackTraces           Hide the stack trace on lambda failure. Default: false
--host                  -o  Host name to listen on. Default: localhost
--httpPort                  Http port to listen on. Default: 3000
--httpsProtocol         -H  To enable HTTPS, specify directory (relative to your cwd, typically your project dir) for both cert.pem and key.pem files
--ignoreJWTSignature        When using HttpApi with a JWT authorizer, don't check the signature of the JWT token. This should only be used for local development.
--lambdaPort                Lambda http port to listen on. Default: 3002
--noPrependStageInUrl       Don't prepend http routes with the stage.
--noAuth                    Turns off all authorizers
--noTimeout             -t  Disables the timeout feature.
--prefix                -p  Adds a prefix to every path, to send your requests to http://localhost:3000/[prefix]/[your_path] instead. Default: ''
--printOutput               Turns on logging of your lambda outputs in the terminal.
--resourceRoutes            Turns on loading of your HTTP proxy settings from serverless.yml
--useChildProcesses         Run handlers in a child process
--useWorkerThreads          Uses worker threads for handlers. Requires node.js v11.7.0 or higher
--websocketPort             WebSocket port to listen on. Default: 3001
--webSocketHardTimeout      Set WebSocket hard timeout in seconds to reproduce AWS limits (https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#apigateway-execution-service-websocket-limits-table). Default: 7200 (2 hours)
--webSocketIdleTimeout      Set WebSocket idle timeout in seconds to reproduce AWS limits (https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#apigateway-execution-service-websocket-limits-table). Default: 600 (10 minutes)
--useDocker                 Run handlers in a docker container.
--layersDir                 The directory layers should be stored in. Default: ${codeDir}/.serverless-offline/layers'
--dockerReadOnly            Marks if the docker code layer should be read only. Default: true
--allowCache                Allows the code of lambda functions to cache if supported.
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59592838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档