Skip to content

Commit

Permalink
Changed name and usig less packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Robsahm committed Nov 30, 2016
1 parent 3ec7be7 commit 72727db
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 70 deletions.
4 changes: 0 additions & 4 deletions app/config/index.js

This file was deleted.

50 changes: 0 additions & 50 deletions app/index.js

This file was deleted.

3 changes: 3 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const varium = require("varium");

module.exports = varium(process.env, "env.manifest");
49 changes: 47 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
require("babel-register");
require("./app");
const ws = require("ws");
const url = require("url");
const config = require("./config");

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

const startUpdateConfig = (environment) => {
let retryNumOfTimes = 0;
let interval;

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

webSocket.on("open", () => {
retryNumOfTimes = 0;
requestConfig(webSocket, environment);
interval = setInterval(
requestConfig,
config.get("INTERVAL"),
webSocket,
environment
);
});

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

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

webSocket.on("close", () => {
clearInterval(interval);
setTimeout(connect, Math.ceil(Math.pow(Math.E, retryNumOfTimes)) * 100);
retryNumOfTimes += 1;
});
};

connect();
};

module.exports = startUpdateConfig;

//startUpdateConfig("dev");
17 changes: 3 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
{
"name": "next-config-applier",
"name": "next-config-client",
"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 ."
"dev-start": "nf run npm run start -s"
},
"author": "",
"author": "Alex Robsahm",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.18.2",
"babel-plugin-transform-exponentiation-operator": "^6.8.0",
"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"
}
Expand Down

0 comments on commit 72727db

Please sign in to comment.