Code Monkey home page Code Monkey logo

Comments (3)

oremut avatar oremut commented on August 12, 2024

This isn't a problem with the js-pdk, so I'm closing this issue.
I found this issue: Kong/kong#6149 where someone said

Environment variables are cleared in the server worker processes by default — this means they are not visible either by Go or Lua plugins.

But you can enable them explicitly using Nginx's env directive. For example, to expose the PATH variable, you can start kong with the following environment variable KONG_NGINX_MAIN_ENV=PATH, and Kong will inject the env directive in Nginx's main configuration section with the value PATH, and that variable should be visible from both Go and Lua.

Exposing the env variables using KONG_NGINX_MAIN_ENV made them visible to my js plugin.

In a lua plugin I wrote we were using environment variables, which is why I thought this was specific to the js pdk, but I was accessing them using the resty.env package, which must have been doing something special under the hood.

from kong-js-pdk.

sinalkar avatar sinalkar commented on August 12, 2024

Exposing the env variables using KONG_NGINX_MAIN_ENV made them visible to my js plugin.

@oremut I tried same but not getting in process.env can you please share how to access

from kong-js-pdk.

oremut avatar oremut commented on August 12, 2024

@sinalkar We are using Helm to deploy Kong in Kubernetes. In my values.yaml file I have NGINX_MAIN_ENV: KONG_REDIS_AUTH_PASSWORD. This gives me access to the env var named KONG_REDIS_AUTH_PASSWORD in my JS plugin. In the JS plugin I can access the env var with:

const process = require('process');

const password = process.env.KONG_REDIS_AUTH_PASSWORD;

If you need to expose more than one env variable you can do it like this in your values file:

NGINX_MAIN_ENV: KONG_REDIS_AUTH_PASSWORD; env ANOTHER_ENV_VAR; env YET_ANOTHER_ENV_VAR;

from kong-js-pdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.