Attempt to remove koa requirement

This commit is contained in:
Jonatan Nilsson 2020-04-07 10:36:11 +00:00
parent 68024783b9
commit bc7b0d7223
5 changed files with 72 additions and 2791 deletions

View file

@ -11,10 +11,9 @@ COPY public $HOME/public
WORKDIR $HOME WORKDIR $HOME
RUN apk add --no-cache make gcc g++ python && \ RUN npm install && \
npm install && \ npm run build && \
apk del make gcc g++ python && \ rm -rf node_modules
npm run build
########################### ###########################
# Server # Server
@ -27,13 +26,10 @@ COPY .babelrc config.js log.js index.js package.json $HOME/
WORKDIR $HOME WORKDIR $HOME
RUN apk add --no-cache make gcc g++ python && \ RUN npm install --production
npm install --production
COPY api $HOME/api COPY api $HOME/api
COPY migrations $HOME/migrations
COPY config $HOME/config COPY config $HOME/config
COPY script $HOME/script
COPY --from=build /app/public $HOME/public COPY --from=build /app/public $HOME/public
EXPOSE 3000 EXPOSE 3000

View file

@ -1,4 +1,4 @@
import bunyan from 'bunyan' import bunyan from 'bunyan-lite'
import defaults from './defaults.mjs' import defaults from './defaults.mjs'
import config from './config.mjs' import config from './config.mjs'

View file

@ -1,6 +1,9 @@
import Koa from 'koa' // import Koa from 'koa'
import serve from 'koa-better-serve' // import serve from 'koa-better-serve'
import socket from 'koa-socket' // import socket from 'koa-socket'
import socket from 'socket.io-serveronly'
import http from 'http'
import nStatic from 'node-static'
import * as casparcg from './casparcg/client.mjs' import * as casparcg from './casparcg/client.mjs'
import lowdb from './db.mjs' import lowdb from './db.mjs'
@ -12,6 +15,62 @@ import { bunyanLogger, errorHandler } from './middlewares.mjs'
log.info('Server: Opening database db.json') log.info('Server: Opening database db.json')
lowdb().then(function(db) { lowdb().then(function(db) {
const fileServer = new nStatic.Server('./public')
const server = http.createServer(function (req, res) {
const child = log.child({})
const d1 = new Date().getTime()
var done = function () {
var requestTime = new Date().getTime() - d1
let level = 'info'
if (res.status >= 400) {
level = 'warn'
}
if (res.status >= 500) {
level = 'error'
}
child[level]({
duration: (d2 - d1),
status: res.statusCode,
}, `<-- ${req.method} ${req.url}`)
}
res.addListener('finish', done);
res.addListener('close', done);
req.addListener('end', function () {
if (req.url === '/') {
res.writeHead(302, { Location: '/index.html' })
return res.end()
}
fileServer.serve(req, res, function (err) {
if (err) {
logger.error(err);
res.writeHead(err.status, err.headers);
res.end(err.message);
}
});
}).resume()
})
const io = new socket(server)
io.on('connection', onConnection.bind(this, io, db))
casparcg.initialise(log, db, io)
server.listen(config.get('server:port'), '0.0.0.0', function(err) {
if (err) {
log.fatal(err)
return process.exit(2)
}
log.info(`Server is listening on ${config.get('server:port')}`)
})
/*
const app = new Koa() const app = new Koa()
const io = new socket() const io = new socket()
@ -34,7 +93,7 @@ lowdb().then(function(db) {
app.listen(config.get('server:port'), err => { app.listen(config.get('server:port'), err => {
if (err) return log.fatal(err) if (err) return log.fatal(err)
log.info(`Server is listening on ${config.get('server:port')}`) log.info(`Server is listening on ${config.get('server:port')}`)
}) })*/
}, function(e) { }, function(e) {
log.fatal(e, 'Critical error loading database') log.fatal(e, 'Critical error loading database')
process.exit(1) process.exit(1)

2772
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@
"start:win": "node --experimental-modules index.mjs | bunyan -o short", "start:win": "node --experimental-modules index.mjs | bunyan -o short",
"dev": "run-p js:watch start:watch", "dev": "run-p js:watch start:watch",
"build": "run-p js:build:main js:build:client js:build:status", "build": "run-p js:build:main js:build:client js:build:status",
"docker": "docker run -it --rm --name my-running-script -p 3000:3000 -v \"%cd%\":/usr/src/app -w /usr/src/app node", "docker": "docker run -it --rm --name my-running-script -p 3000:3000 -v \"%cd%\":/usr/src/app -w /usr/src/app node:alpine",
"docker:install": "npm run docker -- npm install", "docker:install": "npm run docker -- npm install",
"docker:dev": "npm run docker -- npm run dev" "docker:dev": "npm run docker -- npm run dev"
}, },
@ -35,18 +35,16 @@
"homepage": "https://github.com/nfp-projects/caspar-sup#readme", "homepage": "https://github.com/nfp-projects/caspar-sup#readme",
"dependencies": { "dependencies": {
"bunyan": "^1.8.12", "bunyan": "^1.8.12",
"bunyan-lite": "^1.0.1",
"casparcg-connection": "4.9.0", "casparcg-connection": "4.9.0",
"koa": "^2.4.1",
"koa-better-serve": "^2.0.7",
"koa-socket": "^4.4.0",
"lodash.template": "^4.5.0", "lodash.template": "^4.5.0",
"lowdb": "^1.0.0", "lowdb": "^1.0.0",
"nconf": "^0.9.1", "nconf": "^0.9.1",
"socket.io": "^2.3.0", "socket.io-serveronly": "^2.3.0",
"tslib": "^1.11.1" "tslib": "^1.11.1"
}, },
"devDependencies": { "devDependencies": {
"asbundle": "TheThing/asbundle", "asbundle": "^2.6.1",
"dragula": "^3.7.2", "dragula": "^3.7.2",
"mithril": "^1.1.5", "mithril": "^1.1.5",
"nodemon": "^2.0.2", "nodemon": "^2.0.2",