0

PROBLEM

I cannot get serverless offline to run when not connected to internet.

serverless.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

To launch serverless offline, I run serverless offline start in terminal. This works when I am connected to the internet, but when offline, I get the following errors:

Console Error

: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

Terminal Error

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

Request

I suspect the cause is because I am not sure how to setup offline using instruction: "The event object passed to your λs has one extra key: { isOffline: true }. Also, process.env.IS_OFFLINE is true."

Any assistance on how to debug the issue would be much appreciated.

Wronski
  • 1,506
  • 3
  • 18
  • 37

1 Answers1

0

Probably you already fix it, but the problem is because app and org attribute

# app and org for use with dashboard.serverless.com
app: my-app
org: my-org

When you use it, serverless will use config set on serverless.com, commonly env var.

To use env var, you can use plugin serverless-dotenv-plugin. This way, you don't need to connect on internet.