Clean up the code

parent b7017621
const bankai = require('bankai/http')
const path = require('path')
const bankaiHTTP = require('bankai/http')
const express = require('express')
const httpsServer = require('@ind.ie/https-server')
const expressWebSocket = require('express-ws')
const path = require('path')
const entryPoint = path.join(__dirname, 'client.js')
const compiler = bankai(entryPoint)
const builder = require('bankai/lib/cmd-build')
const webBuilder = require('bankai/lib/cmd-build')
// Create the Express app, the HTTPS server, and add WebSocket support.
const app = express()
const server = httpsServer.createServer({}, app)
expressWebSocket(app, server, { perMessageDeflate: false })
......@@ -28,28 +26,43 @@ app.ws('/echo', (webSocket, request) => {
//
// 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><style>body{background-color: "white";}</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, I am an HTTPS GET route!</body></html>')
})
// Finally, if in development, use Bankai to compile assets with live reload.
// If we’re in production, use express.static to serve the dist folder.
const entryPoint = path.join(__dirname, 'client.js')
// 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'})
//
// Production mode.
//
console.log(' 🔒 [hypha] Production mode\n')
// Build the static distribution.
webBuilder(entryPoint, null, {base: 'https://localhost'})
// TODO: Extend cmd-build to emit a done event so we can listen for it.
// TODO: Disable SSR.
// And serve it.
// Serve the static distribution.
app.use(express.static('dist'))
} else {
console.log(' * Development mode')
app.use(compiler)
//
// Development mode.
//
console.log(' 👷 [hypha] Development mode\n')
const webCompilerMiddleware = bankaiHTTP(entryPoint)
app.use(webCompilerMiddleware)
}
// Start the server.
server.listen(443, () => {
console.log('Listening on port 443.')
console.log(' 📡 [hypha] Server running on port 443.\n')
})
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