Commit 2c1b8c19 authored by Aral Balkan's avatar Aral Balkan

Decache routes.js and WebSocket routes; kill hugo server pre-restart

parent b3702355
......@@ -419,7 +419,9 @@ class Site {
// If we need to load dynamic routes from a routesJS file, do it now.
if (this.routesJsFile !== undefined) {
this.createWebSocketServer()
require(path.resolve(this.routesJsFile))(this.app)
const routesJSFilePath = path.resolve(this.routesJsFile)
decache(routesJSFilePath)
require(routesJSFilePath)(this.app)
}
// If there are WebSocket routes, create a regular WebSocket server and
......@@ -428,6 +430,7 @@ class Site {
this.createWebSocketServer()
this.wssRoutes.forEach(route => {
console.log(` 🐁 Adding WebSocket (WSS) route: ${route.path}`)
decache(route.callback)
this.app.ws(route.path, require(route.callback))
})
}
......@@ -551,6 +554,11 @@ class Site {
this.goodbye = (done) => {
console.log('\n 💃 Preparing to exit gracefully, please wait…')
if (this.hugoServerProcess) {
console.log('\n 🚮 Killing Hugo server process.')
this.hugoServerProcess.kill()
}
// Close all active connections on the server.
// (This is so that long-running connections – e.g., WebSockets – do not block the exit.)
this.server.destroy()
......@@ -770,6 +778,11 @@ class Site {
Graceful.off('SIGINT', this.goodbye)
Graceful.off('SIGTERM', this.goodbye)
if (this.hugoServerProcess) {
console.log('\n 🚮 Killing Hugo server process.')
this.hugoServerProcess.kill()
}
// Destroy the current server (so we do not get a port conflict on restart before
// we’ve had a chance to terminate our own process).
this.server.destroy()
......
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