@ditojs/server 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditojs/server",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Dito.js Server – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
|
|
6
6
|
"repository": "https://github.com/ditojs/dito/tree/master/packages/server",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"pg": "^8.7.3",
|
|
82
82
|
"sqlite3": "^5.0.2"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "ec436ef535d96b1653914df6194cc865dfe16ead"
|
|
85
85
|
}
|
package/src/app/Application.js
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
import {
|
|
43
43
|
attachLogger,
|
|
44
44
|
createTransaction,
|
|
45
|
+
ensureRunning,
|
|
45
46
|
findRoute,
|
|
46
47
|
handleError,
|
|
47
48
|
handleRoute,
|
|
@@ -74,7 +75,6 @@ export class Application extends Koa {
|
|
|
74
75
|
log = {},
|
|
75
76
|
...rest
|
|
76
77
|
} = config
|
|
77
|
-
this.server = null
|
|
78
78
|
this.config = {
|
|
79
79
|
app,
|
|
80
80
|
log: log.silent || process.env.DITO_SILENT ? {} : log,
|
|
@@ -89,6 +89,9 @@ export class Application extends Koa {
|
|
|
89
89
|
this.models = Object.create(null)
|
|
90
90
|
this.services = Object.create(null)
|
|
91
91
|
this.controllers = Object.create(null)
|
|
92
|
+
this.server = null
|
|
93
|
+
this.isRunning = false
|
|
94
|
+
|
|
92
95
|
this.setupLogger()
|
|
93
96
|
this.setupKnex()
|
|
94
97
|
this.setupMiddleware(middleware)
|
|
@@ -107,10 +110,6 @@ export class Application extends Koa {
|
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
get isRunning() {
|
|
111
|
-
return !!this.server
|
|
112
|
-
}
|
|
113
|
-
|
|
114
113
|
addRoute(
|
|
115
114
|
method, path, transacted, middlewares, controller = null, action = null
|
|
116
115
|
) {
|
|
@@ -509,6 +508,7 @@ export class Application extends Koa {
|
|
|
509
508
|
|
|
510
509
|
// Setup global middleware
|
|
511
510
|
|
|
511
|
+
this.use(ensureRunning(this))
|
|
512
512
|
this.use(attachLogger(this.logger))
|
|
513
513
|
if (app.responseTime !== false) {
|
|
514
514
|
this.use(responseTime(getOptions(app.responseTime)))
|
|
@@ -731,6 +731,7 @@ export class Application extends Koa {
|
|
|
731
731
|
if (!this.server) {
|
|
732
732
|
throw new Error('Unable to start Dito.js server')
|
|
733
733
|
}
|
|
734
|
+
this.isRunning = true
|
|
734
735
|
await this.emit('after:start')
|
|
735
736
|
}
|
|
736
737
|
|
|
@@ -741,6 +742,7 @@ export class Application extends Koa {
|
|
|
741
742
|
|
|
742
743
|
const promise = (async () => {
|
|
743
744
|
await this.emit('before:stop')
|
|
745
|
+
this.isRunning = false
|
|
744
746
|
await new Promise((resolve, reject) => {
|
|
745
747
|
this.server.close(toPromiseCallback(resolve, reject))
|
|
746
748
|
})
|
|
@@ -150,12 +150,12 @@ export class AdminController extends Controller {
|
|
|
150
150
|
this.app.once('before:stop', () => {
|
|
151
151
|
// For good timing it seems crucial to not add more ticks with async
|
|
152
152
|
// signature, so we directly return the `server.close()` promise instead.
|
|
153
|
-
process.exit = exit
|
|
154
153
|
if (!closed) {
|
|
155
154
|
closed = true
|
|
156
155
|
return server.close()
|
|
157
156
|
}
|
|
158
157
|
})
|
|
158
|
+
|
|
159
159
|
this.koa.use(handleConnectMiddleware(server.middlewares, {
|
|
160
160
|
expandMountPath: true
|
|
161
161
|
}))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function ensureRunning(app) {
|
|
2
|
+
return async (ctx, next) => {
|
|
3
|
+
if (app.isRunning) {
|
|
4
|
+
await next()
|
|
5
|
+
} else {
|
|
6
|
+
// When the app isn't running, e.g. while stopping, we don't want to send
|
|
7
|
+
// content back anymore even if the controllers would still respond. This
|
|
8
|
+
// is to avoid strange behavior during shut-down of the vite dev server.
|
|
9
|
+
// For that scenario, sending back an empty 205 response seems to work.
|
|
10
|
+
ctx.status = 205 // HTTP_RESET_CONTENT
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|