Browse Source

refactor: Move server entrypoints to bin folder

update-deps
Alex Mikhalev 6 years ago
parent
commit
fce64f3850
  1. 6
      package.json
  2. 0
      server/bin/prettyPrint.ts
  3. 27
      server/bin/server.ts
  4. 32
      server/index.ts
  5. 2
      server/sprinklersRpc/index.ts

6
package.json

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": true,
"description": "A frontend for mqtt based IoT sprinklers systems",
"main": "dist/index.js",
"main": "dist/bin/server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rm -rf ./dist ./build ./public",
@ -14,8 +14,8 @@ @@ -14,8 +14,8 @@
"watch:server": "yarn build:server --watch",
"start:dev-server": "NODE_ENV=development webpack-dev-server --config ./client/webpack.config.js --env dev",
"start": "NODE_ENV=development node .",
"start:pretty": "yarn start | node dist/logging/prettyPrint.js",
"start:nodemon": "nodemon --delay 0.5 --exec \"env NODE_ENV=development node . | node dist/logging/prettyPrint.js\"",
"start:pretty": "yarn start | node dist/bin/prettyPrint.js",
"start:nodemon": "nodemon --delay 0.5 --exec \"env NODE_ENV=development node . | node dist/bin/prettyPrint.js\"",
"start:watch": "run-p watch:server start:nodemon",
"start:dev": "run-p start:dev-server start:watch",
"lint:client": "tslint --project client --force --format verbose",

0
server/logging/prettyPrint.ts → server/bin/prettyPrint.ts

27
server/bin/server.ts

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
import * as http from "http";
import * as WebSocket from "ws";
import log from "@common/logger";
import { createApp, ServerState, WebSocketApi } from "../";
const state = new ServerState();
const app = createApp(state);
const webSocketApi = new WebSocketApi(state);
const port = +(process.env.PORT || 8080);
const host = process.env.HOST || "0.0.0.0";
const server = new http.Server(app);
const webSocketServer = new WebSocket.Server({ server });
webSocketApi.listen(webSocketServer);
state
.start()
.then(() => {
server.listen(port, host, () => {
log.info(`listening at ${host}:${port}`);
});
})
.catch(err => {
log.error({ err }, "error starting server");
});

32
server/index.ts

@ -4,32 +4,6 @@ import "./configureAlias"; @@ -4,32 +4,6 @@ import "./configureAlias";
import "./env";
import "./configureLogger";
import log from "@common/logger";
import { Server } from "http";
import * as WebSocket from "ws";
import { ServerState } from "./state";
import { createApp } from "./express";
import { WebSocketApi } from "./sprinklersRpc/WebSocketApi";
const state = new ServerState();
const app = createApp(state);
const webSocketApi = new WebSocketApi(state);
const port = +(process.env.PORT || 8080);
const host = process.env.HOST || "0.0.0.0";
const server = new Server(app);
const webSocketServer = new WebSocket.Server({ server });
webSocketApi.listen(webSocketServer);
state
.start()
.then(() => {
server.listen(port, host, () => {
log.info(`listening at ${host}:${port}`);
});
})
.catch(err => {
log.error({ err }, "error starting server");
});
export { ServerState } from "./state";
export { createApp } from "./express";
export { WebSocketApi } from "./sprinklersRpc/";

2
server/sprinklersRpc/index.ts

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
export * from "./WebSocketApi";
export * from "./WebSocketConnection";
Loading…
Cancel
Save