Comments (9)
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.
Why? Shouldn't \\\\.\pipe\ad443a91-dc7e-4222-a95a-6e64a2554faf
work?
from configuration.
Because IIS populates the PORT env variable
from configuration.
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.
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.
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.
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:
-
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!) -
A configuration json file is set-up that looks like:
{
"port": "PORT"
}
- 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.
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.
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)
- PR: Support modules in config
- <NODE_ENV>.json config need deep merge options HOT 2
- Configuration should recursively go through the values HOT 4
- A way to have local override HOT 1
- Make this repo more about managing configuration HOT 6
- Deprecate v1 in favour of node-config
- Configuration Management HOT 4
- Move config options to app.config instead of the Express app object. HOT 1
- Why use "NODE_ENV=development" with default.json? HOT 3
- Docs are wrong HOT 2
- Stuck in configuration loophole... HOT 3
- Nested configuration HOT 2
- Getting Env name HOT 5
- Prevent automatic expansion of environment variables HOT 13
- Feathers writing in typescript fails to boot on configuration HOT 2
- Missing TypeScript declaration file HOT 10
- Config adding a value of userName in runtime its overwritten to the OS name HOT 1
- Investigate node-config HOT 19
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from configuration.