Restore and organize wonders-server

This commit is contained in:
Kenneth Allen 2021-10-22 18:40:52 +11:00
parent a19445e88e
commit e721b8f357
5 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,23 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"standard"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"comma-dangle": ["error", "only-multiline"],
"padded-blocks": "warn",
"no-multiple-empty-lines": "warn",
"space-before-function-paren": "off"
}
}

View File

@ -0,0 +1,20 @@
FROM node:16-alpine
RUN apk add --no-cache tini
RUN yarn global add lerna
WORKDIR /opt/wonders-server
COPY packages/ketchup-common/package.json packages/ketchup-common/
COPY packages/ketchup-server/package.json packages/ketchup-server/
COPY packages/wonders-common/package.json packages/wonders-common/
COPY packages/wonders-server/package.json packages/wonders-server/
COPY package.json yarn.lock lerna.json ./
RUN lerna bootstrap
COPY . ./
RUN lerna run build
ENTRYPOINT ["tini", "--"]
CMD ["node", "packages/wonders-server"]
EXPOSE 80

View File

@ -0,0 +1,36 @@
{
"name": "wonders-server",
"version": "0.1.3",
"description": "WebSocket-based rollback state synchronization server.",
"main": "dist/index.js",
"license": "MIT",
"private": true,
"dependencies": {
"ketchup-server": "^0.1.1",
"lodash": "^4.17.20",
"wonders-common": "^0.1.1",
"ts-node": "^9.1.1",
"ws": "^7.4.2"
},
"devDependencies": {
"@tsconfig/node14": "^1.0.0",
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.22",
"@types/ws": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"eslint": "^7.18.0",
"jest": "^26.6.3",
"ts-jest": "^26.5.0",
"typescript": "^4.1.3"
},
"optionalDependencies": {
"bufferutil": "^4.0.3",
"utf-8-validate": "^5.0.4"
},
"scripts": {
"build": "tsc --declaration",
"start": "node dist"
}
}

View File

@ -0,0 +1,22 @@
import WebSocket from 'ws'
import KetchupServer from 'ketchup-server'
import { initial, reducer } from 'wonders-common'
const port = parseInt(process.env.PORT ?? '80')
const wss = new WebSocket.Server({ port })
const ks = new KetchupServer(initial, reducer)
wss.on('connection', ws => {
ks.addRemoteClient(ws)
})
console.log(`Listening on ${port}`)
function shutdown() {
console.log('Shutting down')
wss.close()
}
process.on('SIGINT', shutdown)
process.on('SIGTERM', shutdown)

View File

@ -0,0 +1,7 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
}
}