Giter Site home page Giter Site logo

Comments (9)

matb33 avatar matb33 commented on May 27, 2024

This causes issues when trying to pass along PORT from IIS. An example PORT can look like this:

\\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf

from configuration.

daffl avatar daffl commented on May 27, 2024

Why? Shouldn't \\\\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf work?

from configuration.

matb33 avatar matb33 commented on May 27, 2024

Because IIS populates the PORT env variable

from configuration.

daffl avatar daffl commented on May 27, 2024

I'm not following. If you set that string as the PORT environment variable it won't be escaped (see https://github.com/feathersjs/feathers-configuration/blob/master/src/index.js#L26). If you set that string directly in the configuration the (admittedly not pretty) \\\\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf should do it.

from configuration.

matb33 avatar matb33 commented on May 27, 2024

iisnode will automatically set the environment variable PORT with a value that looks like\\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf. The developer does not set this. The value could change. IIS likely generates this thing and iisnode likely sets it as the PORT environment variable for node to consume.

iisnode then assumes you will run your server on port process.env.PORT.

That being said, if one wants to leverage feathers-configuration and is stuck with having to use iisnode, they can't pass along PORT without the leading backslash being removed.

I've implemented a hack workaround to get us through this situation. I'm not entirely sure why this package is changing the values being passed through -- I assume there's a good reason, but it was certainly surprising to have environment variable values changed out from underneath us.

from configuration.

daffl avatar daffl commented on May 27, 2024

I can't test this on Windows but I just verified on Mac OS that an environment variable with two leading backslashes will not be escaped.

from configuration.

matb33 avatar matb33 commented on May 27, 2024

Are you saying that the code here did not remove the first backslash?
https://github.com/feathersjs/feathers-configuration/blob/master/src/index.js#L23-L24

It's sounding more and more like there's a miscommunication going on. I can only continue stressing that the PORT environment variable is set automatically by iisnode. I can't go and change it and add extra backslashes to compensate because the value is automatically generated.

I think perhaps you are confusing this issue with the escaping functionality itself. Your escaping functionality is working as you intended. What I'm trying to bring to light is that the value of an environment variable with leading backslashes will have its first backslash trimmed off.

Example:

  1. A node management process (such as iisnode) automatically sets up some environment variables, among them being PORT with the value \\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf (this CANNOT be changed!)

  2. A configuration json file is set-up that looks like:

{
   "port": "PORT"
}
  1. A boot-up script that looks like:
import feathers from 'feathers'
import configuration from 'feathers-configuration'
import { createServer } from 'https'

const app = feathers()
app.configure(configuration())
const port = app.get('port')
const server = createServer({}, app).listen(port)

In such a scenario, the environment variable PORT will be changed from

\\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf

to

\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf

from configuration.

daffl avatar daffl commented on May 27, 2024

That's what I am trying to say. The environment variable will not be read until https://github.com/feathersjs/feathers-configuration/blob/master/src/index.js#L26 when the part of the code that removes the leading slash is already skipped (because 'PORT'.indexOf('\\') !== 0).

I was able to confirm this again on Mac OS by creating a new folder with an app.js like:

const feathers = require('feathers');
const configuration = require('feathers-configuration');

const app = feathers().configure(configuration());

console.log(app.get('test'))

A config/default.json like:

{
  "test": "PORT"
}

Then I ran

$ npm install feathers feathers-configuration
$ export PORT="\\\\.\\pipe\\ad443a91-dc7e-4222-a95a-6e64a2554faf"
$ echo $PORT
\\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf

And running node app.js shows:

$ node app.js
\\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf

from configuration.

matb33 avatar matb33 commented on May 27, 2024

OK, I see it -- apologies.

That leading backslash is likely getting dropped elsewhere, probably as part of our code.

When I looked at your code, what threw me off was the var name value, and how if we were to suppose value was the environment variable's value, that little bit:

          if (value.indexOf('\\') === 0) {
            value = value.replace('\\', '');
          } else {

would have actually stripped leading backslashes, so it was a perfect combination of red herrings...

Thanks for your patience @daffl

from configuration.

Related Issues (19)

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.