简体   繁体   English

无法获取路径:/{proxy+} 工作(无服务器离线)

[英]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.

相关问题 serverless-offline 可选路径参数 - serverless-offline optional path parameter 无服务器离线 - API REST 节点 typescript - Serverless-offline - API REST node typescript 带有无服务器离线阶段中断路由的 aws-serverless-express - aws-serverless-express with serverless-offline stage breaks routing 如何摆脱包装无服务器离线 html 响应正文的双引号? - How to get rid of double quotes wrapping serverless-offline html response body? 如何在 function 之前在 mocha 测试中启动 serverless-offline - How to start serverless-offline in mocha test before function 在本地 docker localhost:8000 中使用 dynamodb 和在 localhost:4500 上运行的 serverless-framework serverless-offline 应用程序 - Using dynamodb in local docker localhost:8000 with serverless-framework serverless-offline application running on localhost:4500 如何在无服务器离线中使用 Cognito 事件/触发器调用 lambda 以进行本地测试 - How to invoke lambda with Cognito event/trigger in serverless-offline for local test Serverless-offline 抛出“配置错误”或“无法读取未定义的属性‘选项’” - Serverless-offline throws "Configuration error" or "Cannot read property 'options' of undefined" 未找到无服务器命令“离线” - Serverless command "offline" not found 无服务器 - 离线插件 - Serverless - offline plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM