This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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
17 changed files
with
295 additions
and
2 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,3 @@ | ||
{ | ||
"disabled": ["jssource.py"] | ||
} |
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,3 @@ | ||
module.exports = { | ||
extends: "hive" | ||
}; |
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,3 @@ | ||
package-lock.json | ||
|
||
/node_modules |
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 @@ | ||
module.exports = require("prettier-config-hive"); |
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,14 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"program": "${workspaceRoot}/app.js", | ||
"env": { | ||
"NODE_ENV": "development" | ||
} | ||
} | ||
] | ||
} |
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,21 @@ | ||
FROM hivesolutions/alpine_dev:latest | ||
|
||
LABEL version="1.0" | ||
LABEL maintainer="Platforme <[email protected]>" | ||
|
||
EXPOSE 8080 | ||
|
||
ENV HOST 0.0.0.0 | ||
ENV PORT 8080 | ||
ENV NODE_ENV production | ||
|
||
ADD app.js /app/ | ||
ADD package.json /app/ | ||
ADD lib /app/lib | ||
|
||
WORKDIR /app | ||
|
||
RUN apk update && apk add nodejs npm | ||
RUN npm install | ||
|
||
CMD ["/usr/bin/node", "/app/app.js"] |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# simple-proxy | ||
Simple proxy pipeline proxy service | ||
# Simple (HTTP) Proxy | ||
|
||
Simple HTTP proxy pipeline service. |
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,76 @@ | ||
// requires the multiple libraries | ||
const bodyParser = require("body-parser"); | ||
const express = require("express"); | ||
const process = require("process"); | ||
const util = require("hive-js-util"); | ||
const info = require("./package"); | ||
const lib = require("./lib"); | ||
const request = require("request"); | ||
|
||
// builds the initial application object to be used | ||
// by the application for serving | ||
const app = express(); | ||
|
||
// ensures that the content type is exposed in the request | ||
// object and that the body is parsed accordingly (JSON | ||
// and URL encoding) | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
|
||
process.on("SIGINT", function() { | ||
process.exit(); | ||
}); | ||
|
||
process.on("SIGTERM", function() { | ||
process.exit(); | ||
}); | ||
|
||
process.on("exit", () => { | ||
util.Logging.info("Exiting on user's request"); | ||
lib.destroy(); | ||
}); | ||
|
||
app.get("/info", (req, res, next) => { | ||
res.json({ | ||
name: info.name, | ||
version: info.version, | ||
node: process.version | ||
}); | ||
}); | ||
|
||
app.all("*", (req, res, next) => { | ||
async function clojure() { | ||
lib.verifyKey(req); | ||
await new Promise(function(resolve, reject) { | ||
try { | ||
// constructs the initial options object with the | ||
// processed headers and query string | ||
const options = { | ||
baseUrl: lib.TARGET, | ||
uri: req.path, | ||
method: req.method, | ||
headers: lib.proxyHeaders(req), | ||
qs: req.query, | ||
forever: true, | ||
pool: { maxSockets: Infinity } | ||
}; | ||
|
||
// runs the changed request with the transformed values so | ||
// that they become compliant with the RIPE API | ||
request(options) | ||
.pipe(res) | ||
.on("finish", resolve) | ||
.on("error", reject); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
} | ||
clojure().catch(next); | ||
}); | ||
|
||
app.listen(lib.PORT, lib.HOSTNAME, () => { | ||
lib.startLogging(); | ||
util.Logging.info("Listening on " + lib.HOSTNAME + ":" + String(lib.PORT)); | ||
lib.init(); | ||
}); |
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,5 @@ | ||
const proxy = require("./proxy"); | ||
const util = require("./util"); | ||
|
||
Object.assign(module.exports, proxy); | ||
Object.assign(module.exports, util); |
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,3 @@ | ||
const proxy = require("./proxy"); | ||
|
||
Object.assign(module.exports, proxy); |
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,21 @@ | ||
function proxyHeaders(req) { | ||
const headers = Object.assign({}, req.headers || {}); | ||
|
||
const skip = ["connection", "content-length", "host"]; | ||
skip.forEach(header => { | ||
delete headers[header]; | ||
}); | ||
|
||
if (!headers["x-forwarded-for"] !== undefined) { | ||
headers["x-forwarded-for"] = req.connection.remoteAddress; | ||
} | ||
if (!headers["x-forwarded-proto"] !== undefined) { | ||
headers["x-forwarded-proto"] = req.protocol; | ||
} | ||
|
||
return headers; | ||
} | ||
|
||
module.exports = { | ||
proxyHeaders: proxyHeaders | ||
}; |
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,29 @@ | ||
const config = require("./config"); | ||
|
||
const init = () => {}; | ||
|
||
const destroy = () => {}; | ||
|
||
/** | ||
* Verifies that the key present in the request matches | ||
* the one defined in the current configuration, ensuring | ||
* that proper security measures are in place. | ||
* | ||
* @param {any} req The request to retrieve the key. | ||
*/ | ||
const verifyKey = req => { | ||
if (!config.KEY) { | ||
return; | ||
} | ||
const _key = req.query.key || req.headers["X-Proxy-Key"] || null; | ||
if (config.KEY === _key) { | ||
return; | ||
} | ||
throw new Error("Invalid key"); | ||
}; | ||
|
||
module.exports = { | ||
init: init, | ||
destroy: destroy, | ||
verifyKey: verifyKey | ||
}; |
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,34 @@ | ||
const util = require("hive-js-util"); | ||
|
||
const HOSTNAME = process.env.HOST ? process.env.HOST : "127.0.0.1"; | ||
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 3000; | ||
const KEY = process.env.PROXY_KEY ? process.env.PROXY_KEY : null; | ||
const TARGET = process.env.PROXY_TARGET | ||
? process.env.PROXY_TARGET | ||
: "https://sandbox.platforme.com/"; | ||
const SDK_URL = process.env.RIPE_SDK_URL | ||
? process.env.RIPE_SDK_URL | ||
: "https://sandbox.platforme.com/api/"; | ||
|
||
const startLogging = () => { | ||
const logger = util.Logging.getLogger(undefined, { | ||
level: util.Logging.constants.DEBUG | ||
}); | ||
|
||
if (util.Logging.ConsolaHandler.isReady()) { | ||
logger.addHandler(new util.Logging.ConsolaHandler()); | ||
logger.setFormatter(new util.Logging.SimpleFormatter("{asctime} {message}")); | ||
} else { | ||
logger.addHandler(new util.Logging.StreamHandler()); | ||
logger.setFormatter(new util.Logging.SimpleFormatter()); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
HOSTNAME: HOSTNAME, | ||
PORT: PORT, | ||
KEY: KEY, | ||
SDK_URL: SDK_URL, | ||
TARGET: TARGET, | ||
startLogging: startLogging | ||
}; |
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,5 @@ | ||
class NotImplementedError extends Error {} | ||
|
||
module.exports = { | ||
NotImplementedError: NotImplementedError | ||
}; |
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,7 @@ | ||
const base = require("./base"); | ||
const config = require("./config"); | ||
const errors = require("./errors"); | ||
|
||
Object.assign(module.exports, base); | ||
Object.assign(module.exports, config); | ||
Object.assign(module.exports, errors); |
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,53 @@ | ||
{ | ||
"name": "simple-proxy", | ||
"version": "0.1.0", | ||
"description": "Simple HTTP proxy for node.js", | ||
"keywords": [ | ||
"http", | ||
"proxy", | ||
"simple" | ||
], | ||
"homepage": "https://github.com/ripe-tech/simple-proxy#readme", | ||
"bugs": { | ||
"url": "https://github.com/ripe-tech/simple-proxy/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ripe-tech/simple-proxy.git" | ||
}, | ||
"license": "Apache-2.0", | ||
"author": "Platforme", | ||
"files": [ | ||
"app.js", | ||
"lib/**/*.css", | ||
"lib/**/*.js", | ||
"test/**/*.js" | ||
], | ||
"main": "app.js", | ||
"scripts": { | ||
"lint": "eslint \"./**/*.js\"", | ||
"lint-fix": "eslint \"./**/*.js\" --fix", | ||
"prettier": "prettier \"./**/*.{js,json}\" --write", | ||
"pretty": "npm run prettier && npm run lint-fix", | ||
"start": "node app.js", | ||
"test": "mocha --recursive", | ||
"upgrade": "npx sort-package-json && ncu -u" | ||
}, | ||
"dependencies": { | ||
"consola": "^2.10.1", | ||
"express": "^4.17.1", | ||
"hive-js-util": "^0.2.1", | ||
"request": "^2.88.0", | ||
"ripe-sdk": "^1.6.43", | ||
"uuid": "^3.3.3" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.4.0", | ||
"eslint-config-hive": "^0.1.22", | ||
"mocha": "^6.2.0", | ||
"npm-check-updates": "^3.1.23", | ||
"prettier": "^1.18.2", | ||
"prettier-config-hive": "^0.1.1", | ||
"sort-package-json": "^1.22.1" | ||
} | ||
} |
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,14 @@ | ||
const assert = require("assert"); | ||
|
||
describe("Array", function() { | ||
describe("#indexOf()", function() { | ||
it("should return -1 when the value is not present", () => { | ||
assert.strictEqual(-1, [1, 2, 3].indexOf(4)); | ||
}); | ||
}); | ||
describe("#length", function() { | ||
it("should return proper length", () => { | ||
assert.strictEqual(3, [1, 2, 3].length); | ||
}); | ||
}); | ||
}); |