Skip to content

Commit

Permalink
Add forwarder
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fox committed Apr 5, 2024
1 parent 2c36f06 commit 1eb01ce
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions forwarder/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
26 changes: 26 additions & 0 deletions forwarder/bin/proxy.js
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);
23 changes: 23 additions & 0 deletions forwarder/package.json
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": []
}

0 comments on commit 1eb01ce

Please sign in to comment.