Skip to content

Commit

Permalink
server: Add v basic backend node server
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Jan 10, 2021
1 parent 2801586 commit 5571968
Show file tree
Hide file tree
Showing 5 changed files with 443 additions and 422 deletions.
11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -9,7 +9,9 @@
"start-main-dev": "webpack --config=webpack.config.main.ts",
"start-renderer-dev": "webpack --config=webpack.config.renderer.ts",
"start-website-dev": "webpack --config=webpack.config.website.ts",
"start-server-dev": "nodemon --watch 'src/**/*' -e ts,tsx --exec ts-node ./src/server/index.ts",
"start": "electron dist/main.js",
"start-server": "ts-node ./src/server/index.ts",
"build-main": "cross-env NODE_ENV=production webpack --config=webpack.config.main.ts",
"build-renderer": "cross-env NODE_ENV=production webpack --config=webpack.config.renderer.ts",
"build-website": "cross-env NODE_ENV=production webpack --config=webpack.config.website.ts",
Expand All @@ -26,11 +28,7 @@
"output": "release"
},
"publish": null,
"files": [
"dist/",
"node_modules/better-sqlite3/**/*",
"package.json"
],
"files": ["dist/", "node_modules/better-sqlite3/**/*", "package.json"],
"linux": {
"target": "tar.gz"
},
Expand All @@ -52,6 +50,7 @@
"jest": "^26.0.1",
"lint-staged": "^10.0.7",
"node-loader": "^1.0.1",
"nodemon": "^2.0.7",
"null-loader": "^4.0.0",
"prettier": "^2.0.5",
"typescript-styled-plugin": "^0.15.0",
Expand Down Expand Up @@ -83,6 +82,7 @@
"@types/electron-settings": "^3.1.1",
"@types/http-proxy": "^1.17.4",
"@types/jest": "^26.0.13",
"@types/koa": "^2.11.6",
"@types/lodash": "^4.14.161",
"@types/module-alias": "^2.0.0",
"@types/node": "14.14.16",
Expand Down Expand Up @@ -119,6 +119,7 @@
"http-proxy": "^1.18.1",
"image-webpack-loader": "^7.0.1",
"ip-address": "^7.0.1",
"koa": "^2.13.1",
"lodash": "^4.17.15",
"mobx": "^5.15.4",
"mobx-react": "^6.2.2",
Expand Down
22 changes: 22 additions & 0 deletions src/server/index.ts
@@ -0,0 +1,22 @@
import Koa from 'koa';
import {Server} from 'socket.io';

import {createServer} from 'http';

const app = new Koa();
const server = createServer(app.callback());

const wss = new Server(server);

wss.of('/ingest').on('connection', socket => {
socket.on('store-init', console.log);
socket.on('store-update', console.log);
});

console.log('here we gooo');

app.use(ctx => {
ctx.body = 'Hello World';
});

server.listen(3000);
12 changes: 11 additions & 1 deletion src/shared/store/ipc.ts
Expand Up @@ -15,7 +15,7 @@ import {
import {deepObserve} from 'mobx-utils';
import {deserialize, serialize, update} from 'serializr';
import {Server} from 'socket.io';
import {Socket} from 'socket.io-client';
import {io, Socket} from 'socket.io-client';

import store, {
AppConfig,
Expand Down Expand Up @@ -351,6 +351,16 @@ export const registerMainWebsocket = (wss: Server) => {
changeHandlers.push(change => wss.sockets.emit('store-update', change));
};

/**
* Pushes updates to the server running on prolink.tools.
*/
export const registerMainPushWebsocker = () => {
const conn = io('http://localhost:3000/ingest');

conn.emit('store-init', serialize(AppStore, store));
changeHandlers.push(change => conn.emit('store-update', change));
};

/**
* Register this client to recieve websocket broadcasts to update the store
*/
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -16,8 +16,9 @@
"paths": {
"src/*": ["./*"],
"app/*": ["./renderer/*"],
"overlay/*": ["./overlay/*"],
"main/*": ["./main/*"],
"overlay/*": ["./overlay/*"],
"server/*": ["./server/*"],
"web/*": ["./website/*"]
},
"plugins": [
Expand Down

1 comment on commit 5571968

@vercel
Copy link

@vercel vercel bot commented on 5571968 Jan 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.