Add production mode

parent 4b8ebee1
Pipeline #784 canceled with stages
node_modules
node_modules
dist/
......@@ -5,20 +5,19 @@ const expressWebSocket = require('express-ws')
const path = require('path')
const websocketRouter = express.Router()
const compiler = bankai(path.join(__dirname, 'client.js'))
const entryPoint = path.join(__dirname, 'client.js')
const compiler = bankai(entryPoint)
const builder = require('bankai/lib/cmd-build')
const app = express()
const server = httpsServer.createServer({}, app)
expressWebSocket(app, server, { perMessageDeflate: false })
// Websocket routes go here
const webSocketServer = expressWebSocket(app, server, {
perMessageDeflate: false
})
//
// Websocket routes go here.
//
// Add web socket routes.
app.ws('/echo', (webSocket, request) => {
webSocket.on('message', message => {
console.log('Got web socket request to echo ', message)
......@@ -26,15 +25,30 @@ app.ws('/echo', (webSocket, request) => {
})
})
// Server-side routes go here.
//
// HTTPS routes go here.
//
app.get('/hello', (request, response) => {
response.writeHeader(200, {'Content-Type': 'text/html'})
response.end('<!doctype html><html lang=\'en\'><head><meta charset=\'utf-8\'/><title>Hello</title></head><body>Hello!</body></html>')
response.end('<!doctype html><html lang=\'en\'><head><meta charset=\'utf-8\'/><title>Hello</title><style>body{background-color: "white";}</head><body>Hello!</body></html>')
})
// Finally, use Bankai.
app.use(compiler)
// Finally, if in development use Bankai to compile assets and for live reload,
// and if we’re in production use express.static to serve the dist folder.
if (process.env.NODE_ENV === 'production') {
console.log(' * Production mode')
// Build for production.
builder(entryPoint, null, {base: 'https://localhost'})
// TODO: Extend cmd-build to emit a done event so we can listen for it.
// And serve it.
app.use(express.static('dist'))
} else {
console.log(' * Development mode')
app.use(compiler)
}
server.listen(443, () => {
console.log('Listening on port 443.')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment