Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Robsahm committed Nov 30, 2016
0 parents commit 1fa4f00
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
"es2015"
],
"plugins": [
"transform-object-rest-spread"
]
}
27 changes: 27 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"env": {
"node": true,
"es6": true
},
"extends": "airbnb",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"rules": {
"no-console": 0,
"no-mixed-operators": 0,
"react/require-extension": 0,
"arrow-body-style": 0,
"no-confusing-arrow": 0,
"import/prefer-default-export": 0,
"new-cap": 0,
"no-underscore-dangle": 0,
"camelcase": 0,
"no-else-return": 0,
"no-process-env": 2,
"quotes": [1, "double"],
"no-console": [2, { "allow": ["error"] }]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules/
4 changes: 4 additions & 0 deletions app/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint no-process-env: 0 */
import varium from "varium";

module.exports = varium(process.env, "env.manifest");
45 changes: 45 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint no-process-env: 0 */

import ws from "ws";
import url from "url";
import config from "./config";

const updateConfig = (webSocket, environment) => {
webSocket.send(environment);
};

export const startUpdateConfig = (environment) => {
const connect = () => {
const webSocket = new ws(url.resolve(config.get("CONFIG_SERVICE_URL"), environment));

webSocket.on("open", () => {
updateConfig(webSocket, environment);
setInterval(
updateConfig,
config.get("INTERVAL"),
webSocket,
environment,
);
});

webSocket.on("message", (message) => {
process.env = {
...process.env,
...JSON.parse(message),
};
});

webSocket.on("error", (error) => {
console.error("Error:", error);
});

webSocket.on("close", () => {
console.error("Socket closed");
setTimeout(connect, 2000);
});
};

connect();
};

startUpdateConfig("dev");
2 changes: 2 additions & 0 deletions env.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INTERVAL : Int
CONFIG_SERVICE_URL : String
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require("babel-register");
require("./app");
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "next-config-applier",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node .",
"dev-start": "nf run npm run test && nf run npm run start -s",
"test": "eslint --fix ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.18.2",
"babel-plugin-transform-object-rest-spread": "^6.19.0",
"babel-preset-es2015": "^6.18.0",
"eslint": "^3.11.1",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.7.1",
"foreman": "^2.0.0"
},
"dependencies": {
"babel-register": "^6.18.0",
"varium": "github:ahultgren/node-varium",
"ws": "^1.1.1"
}
}

0 comments on commit 1fa4f00

Please sign in to comment.