serverless-cloudflare-workers icon indicating copy to clipboard operation
serverless-cloudflare-workers copied to clipboard

Environment Vars Not Working

Open matt-lethargic opened this issue 6 years ago • 1 comments

I'm trying to get environment variables working as described in the documentation but not having any lucky.

serverless.yml

service:
name: library

provider:
  name: cloudflare
  stage: systest
  config:
    accountId: <somestring>
    zoneId: <anotherstirng>
  environment:
    MY_TEST: HELLO

plugins:
  - serverless-cloudflare-workers

functions:
  library:
    name: library
    script: handlers/test
    environment:
      MY_TEST: WORLD
    events:
      - http:
        url: docs.somedomain.com/*
        method: GET

test.js

addEventListener('fetch', event => {
  event.respondWith(handle(event))
})

async function handle(event) {

  console.log('MY_TEST: ', process.env.MY_TEST);

  return new Response(null, { status: 200 });
}

I've tried process.env.MY_TEST and just plain old MY_TEST and no luck.

matt-lethargic avatar Jul 09 '19 10:07 matt-lethargic

@matt-lethargic I've no real experience using this plugin. However, it seems that this plugin has been deprecated in favor of wrangler. Wrangler does not offer support for Env variables either.

One thing that you could do is use webpack to inject global variables at build time with their DefinePlugin#

VerstraeteBert avatar Aug 16 '19 04:08 VerstraeteBert