cloudflare / serverless-cloudflare-workers

Serverless provider plugin for Cloudflare Workers
BSD 3-Clause "New" or "Revised" License
175 stars 37 forks source link

Environment Vars Not Working #43

Open matt-lethargic opened 5 years ago

matt-lethargic commented 5 years ago

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.

VerstraeteBert commented 5 years ago

@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#