问题
未连接到 Internet 时,我无法让无服务器脱机运行。
无服务器.yml
service: my-app
plugins:
- serverless-offline
# run on port 4000, because client runs on 3000
custom:
serverless-offline:
port: 4000
# app and org for use with dashboard.serverless.com
app: my-app
org: my-org
provider:
name: aws
runtime: nodejs10.x
functions:
getData:
handler: data-service.getData
events:
- http:
path: data/get
method: get
cors: true
isOffline: true
saveData:
handler: data-service.saveData
events:
- http:
path: data/save
method: put
cors: true
isOffline: true
要离线启动无服务器,我serverless offline start
在终端中运行。这在我连接到互联网时有效,但在离线时,我收到以下错误:
控制台错误
:4000/data/get:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
20:34:02.820 localhost/:1 Uncaught (in promise) TypeError: Failed to fetch
终端错误
FetchError: request to https://api.serverless.com/core/tenants/{tenant}/applications/my-app/profileValue failed, reason: getaddrinfo ENOTFOUND api.serverless.com api.serverless.com:443
要求
我怀疑原因是因为我不确定如何使用指令设置离线:“传递给您的 λs 的事件对象有一个额外的键:{ isOffline: true }
。而且,process.env.IS_OFFLINE
是真的。”
任何有关如何调试问题的帮助将不胜感激。