-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// include dependencies | ||
const express = require('express'); | ||
const debug = require('debug')('broker:proxy'); | ||
const { createProxyMiddleware } = require('http-proxy-middleware'); | ||
|
||
const app = express(); | ||
|
||
const target = process.env.CONTEXT_BROKER || 'http://orion:1026'; | ||
const tenant = process.env.TENANT || 'farmer'; | ||
|
||
// create the proxy | ||
/** @type {import('http-proxy-middleware/dist/types').RequestHandler<express.Request, express.Response>} */ | ||
const exampleProxy = createProxyMiddleware({ | ||
target, // target host with the same base path | ||
changeOrigin: true, // needed for virtual hosted sites | ||
on: { | ||
proxyReq: (proxyReq, req, res) => { | ||
debug(req.originalUrl); | ||
proxyReq.setHeader('NGSILD-Tenant', tenant); | ||
} | ||
} | ||
}); | ||
|
||
// mount `exampleProxy` in web server | ||
app.use('/', exampleProxy); | ||
app.listen(80); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "proxy", | ||
"license": "AGPL-3.0-only", | ||
"description": "Simple forwarding proxy", | ||
"version": "1.0.0", | ||
"main": "bin/proxy.js", | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"scripts": { | ||
"start": "node ./bin/proxy", | ||
"prettier": "prettier --parser flow --single-quote --write **/**/*.js **/*.js *.js" | ||
}, | ||
"dependencies": { | ||
"debug": "^4.3.4", | ||
"express": "^4.19.2", | ||
"http-proxy-middleware": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"prettier": "~1.14.2" | ||
}, | ||
"keywords": [] | ||
} |