Skip to content

Commit

Permalink
v6.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dherault committed May 28, 2020
1 parent 3ca8048 commit 8755d9d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -174,6 +174,10 @@ aws lambda invoke /dev/null \
--function-name myServiceName-dev-invokedHandler
```

## The `process.env.IS_OFFLINE` variable

Will be `"true"` in your handlers and thourough the plugin.

## Token authorizers

As defined in the [Serverless Documentation](https://serverless.com/framework/docs/providers/aws/events/apigateway/#setting-api-keys-for-your-rest-api) you can use API Keys as a simple authentication method.
Expand Down
4 changes: 1 addition & 3 deletions examples/events/http/handler.js
@@ -1,10 +1,8 @@
'use strict'

const { stringify } = JSON

exports.hello = async function hello() {
return {
body: stringify({ foo: 'bar' }),
body: JSON.stringify({ foo: 'bar', IS_OFFLINE: process.env.IS_OFFLINE }),
statusCode: 200,
}
}
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"dedicatedTo": "Blue, a great migrating bird.",
"name": "serverless-offline",
"version": "6.2.0",
"version": "6.3.0",
"description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
"license": "MIT",
"main": "dist/main.js",
Expand Down
3 changes: 3 additions & 0 deletions src/ServerlessOffline.js
Expand Up @@ -58,6 +58,9 @@ export default class ServerlessOffline {

// Entry point for the plugin (sls offline) when running 'sls offline start'
async start() {
// Put here so available everywhere, not just in handlers
process.env.IS_OFFLINE = true

// check if update is available
updateNotifier({ pkg }).notify()

Expand Down
@@ -1,7 +1,5 @@
import { performance } from 'perf_hooks'

const { assign } = Object

export default class InProcessRunner {
#env = null
#functionKey = null
Expand Down Expand Up @@ -35,7 +33,7 @@ export default class InProcessRunner {
// NOTE: Don't use Object spread (...) here!
// otherwise the values of the attached props are not coerced to a string
// e.g. process.env.foo = 1 should be coerced to '1' (string)
assign(process.env, this.#env)
Object.assign(process.env, this.#env)

// lazy load handler with first usage

Expand Down

0 comments on commit 8755d9d

Please sign in to comment.