@ditojs/server 1.5.2 → 1.5.5
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 +17 -19
- package/src/app/Application.js +5 -5
- package/src/cli/db/migrate.js +2 -2
- package/src/cli/db/reset.js +2 -2
- package/src/cli/db/rollback.js +2 -2
- package/src/cli/db/unlock.js +2 -2
- package/src/cli/index.js +7 -5
- package/src/controllers/AdminController.js +21 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditojs/server",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
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",
|
|
@@ -21,23 +21,23 @@
|
|
|
21
21
|
"node >= 16"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@ditojs/admin": "^1.5.
|
|
25
|
-
"@ditojs/build": "^1.5.
|
|
26
|
-
"@ditojs/router": "^1.5.
|
|
27
|
-
"@ditojs/utils": "^1.5.
|
|
24
|
+
"@ditojs/admin": "^1.5.5",
|
|
25
|
+
"@ditojs/build": "^1.5.5",
|
|
26
|
+
"@ditojs/router": "^1.5.5",
|
|
27
|
+
"@ditojs/utils": "^1.5.5",
|
|
28
28
|
"@koa/cors": "^3.3.0",
|
|
29
29
|
"@koa/multer": "^3.0.0",
|
|
30
30
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
31
31
|
"ajv": "^8.11.0",
|
|
32
32
|
"ajv-formats": "^2.1.1",
|
|
33
|
-
"aws-sdk": "^2.
|
|
34
|
-
"axios": "^0.
|
|
33
|
+
"aws-sdk": "^2.1131.0",
|
|
34
|
+
"axios": "^0.27.2",
|
|
35
35
|
"bcryptjs": "^2.4.3",
|
|
36
36
|
"bytes": "^3.1.2",
|
|
37
37
|
"data-uri-to-buffer": "^4.0.0",
|
|
38
38
|
"eventemitter2": "^6.4.5",
|
|
39
39
|
"file-type": "^17.1.1",
|
|
40
|
-
"fs-extra": "^10.0
|
|
40
|
+
"fs-extra": "^10.1.0",
|
|
41
41
|
"image-size": "^1.0.1",
|
|
42
42
|
"is-svg": "^4.3.2",
|
|
43
43
|
"koa": "^2.13.4",
|
|
@@ -55,31 +55,29 @@
|
|
|
55
55
|
"mime-types": "^2.1.35",
|
|
56
56
|
"multer": "^1.4.4",
|
|
57
57
|
"multer-s3": "^2.10.0",
|
|
58
|
-
"nanoid": "^3.3.
|
|
58
|
+
"nanoid": "^3.3.4",
|
|
59
59
|
"parse-duration": "^1.0.2",
|
|
60
60
|
"passport-local": "^1.0.0",
|
|
61
61
|
"passthrough-counter": "^1.0.0",
|
|
62
62
|
"picocolors": "^1.0.0",
|
|
63
63
|
"picomatch": "^2.3.1",
|
|
64
|
-
"pino": "^7.
|
|
65
|
-
"pino-pretty": "^7.6.
|
|
64
|
+
"pino": "^7.11.0",
|
|
65
|
+
"pino-pretty": "^7.6.1",
|
|
66
66
|
"pluralize": "^8.0.0",
|
|
67
67
|
"repl": "^0.1.3",
|
|
68
68
|
"uuid": "^8.3.2",
|
|
69
|
-
"vite": "^2.9.
|
|
70
|
-
"vite-plugin-vue2": "^
|
|
69
|
+
"vite": "^2.9.8",
|
|
70
|
+
"vite-plugin-vue2": "^2.0.0",
|
|
71
71
|
"vue": "^2.6.14",
|
|
72
72
|
"vue-template-compiler": "^2.6.14"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"knex": "^1.0.
|
|
75
|
+
"knex": "^1.0.5",
|
|
76
76
|
"objection": "^3.0.1"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"knex": "^
|
|
80
|
-
"objection": "^3.0.1"
|
|
81
|
-
"pg": "^8.7.3",
|
|
82
|
-
"sqlite3": "^5.0.2"
|
|
79
|
+
"knex": "^2.0.0",
|
|
80
|
+
"objection": "^3.0.1"
|
|
83
81
|
},
|
|
84
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "157b519f3f3552fb25b67adf7e0fd402485ac4c9"
|
|
85
83
|
}
|
package/src/app/Application.js
CHANGED
|
@@ -74,7 +74,6 @@ export class Application extends Koa {
|
|
|
74
74
|
log = {},
|
|
75
75
|
...rest
|
|
76
76
|
} = config
|
|
77
|
-
this.server = null
|
|
78
77
|
this.config = {
|
|
79
78
|
app,
|
|
80
79
|
log: log.silent || process.env.DITO_SILENT ? {} : log,
|
|
@@ -89,6 +88,9 @@ export class Application extends Koa {
|
|
|
89
88
|
this.models = Object.create(null)
|
|
90
89
|
this.services = Object.create(null)
|
|
91
90
|
this.controllers = Object.create(null)
|
|
91
|
+
this.server = null
|
|
92
|
+
this.isRunning = false
|
|
93
|
+
|
|
92
94
|
this.setupLogger()
|
|
93
95
|
this.setupKnex()
|
|
94
96
|
this.setupMiddleware(middleware)
|
|
@@ -107,10 +109,6 @@ export class Application extends Koa {
|
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
get isRunning() {
|
|
111
|
-
return !!this.server
|
|
112
|
-
}
|
|
113
|
-
|
|
114
112
|
addRoute(
|
|
115
113
|
method, path, transacted, middlewares, controller = null, action = null
|
|
116
114
|
) {
|
|
@@ -731,6 +729,7 @@ export class Application extends Koa {
|
|
|
731
729
|
if (!this.server) {
|
|
732
730
|
throw new Error('Unable to start Dito.js server')
|
|
733
731
|
}
|
|
732
|
+
this.isRunning = true
|
|
734
733
|
await this.emit('after:start')
|
|
735
734
|
}
|
|
736
735
|
|
|
@@ -741,6 +740,7 @@ export class Application extends Koa {
|
|
|
741
740
|
|
|
742
741
|
const promise = (async () => {
|
|
743
742
|
await this.emit('before:stop')
|
|
743
|
+
this.isRunning = false
|
|
744
744
|
await new Promise((resolve, reject) => {
|
|
745
745
|
this.server.close(toPromiseCallback(resolve, reject))
|
|
746
746
|
})
|
package/src/cli/db/migrate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pico from 'picocolors'
|
|
2
2
|
|
|
3
|
-
export async function migrate(knex) {
|
|
4
|
-
const [batch, log] = await knex.migrate.latest()
|
|
3
|
+
export async function migrate(knex, config) {
|
|
4
|
+
const [batch, log] = await knex.migrate.latest(config)
|
|
5
5
|
console.info(log.length === 0
|
|
6
6
|
? pico.cyan('Already up to date')
|
|
7
7
|
: pico.green(`Batch ${batch} run: ${log.length} migrations\n`) +
|
package/src/cli/db/reset.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import pico from 'picocolors'
|
|
2
2
|
import { migrate } from './migrate.js'
|
|
3
3
|
|
|
4
|
-
export async function reset(knex) {
|
|
4
|
+
export async function reset(knex, config) {
|
|
5
5
|
const batches = []
|
|
6
6
|
const migrations = []
|
|
7
7
|
while (true) {
|
|
8
|
-
const [batch, log] = await knex.migrate.rollback()
|
|
8
|
+
const [batch, log] = await knex.migrate.rollback(config)
|
|
9
9
|
if (log.length === 0) break
|
|
10
10
|
batches.push(batch)
|
|
11
11
|
migrations.push(...log)
|
package/src/cli/db/rollback.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pico from 'picocolors'
|
|
2
2
|
|
|
3
|
-
export async function rollback(knex) {
|
|
4
|
-
const [batch, log] = await knex.migrate.rollback()
|
|
3
|
+
export async function rollback(knex, config) {
|
|
4
|
+
const [batch, log] = await knex.migrate.rollback(config)
|
|
5
5
|
console.info(log.length === 0
|
|
6
6
|
? pico.cyan('Already at the base migration')
|
|
7
7
|
: pico.green(`Batch ${batch} rolled back: ${log.length} migrations\n`) +
|
package/src/cli/db/unlock.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pico from 'picocolors'
|
|
2
2
|
|
|
3
|
-
export async function unlock(knex) {
|
|
4
|
-
await knex.migrate.forceFreeMigrationsLock()
|
|
3
|
+
export async function unlock(knex, config) {
|
|
4
|
+
await knex.migrate.forceFreeMigrationsLock(config)
|
|
5
5
|
console.info(
|
|
6
6
|
pico.green(`Successfully unlocked the migrations lock table`)
|
|
7
7
|
)
|
package/src/cli/index.js
CHANGED
|
@@ -8,10 +8,6 @@ import { isPlainObject, isFunction, camelize } from '@ditojs/utils'
|
|
|
8
8
|
import * as db from './db/index.js'
|
|
9
9
|
import startConsole from './console.js'
|
|
10
10
|
|
|
11
|
-
// Tell Knex to use ESM. TODO: Fix this properly in Knex itself, so it works
|
|
12
|
-
// with Yarn too.
|
|
13
|
-
process.env.npm_package_type = 'module'
|
|
14
|
-
|
|
15
11
|
const commands = { db, console: startConsole }
|
|
16
12
|
|
|
17
13
|
function getCommand(commands, parts) {
|
|
@@ -44,8 +40,14 @@ async function execute() {
|
|
|
44
40
|
}
|
|
45
41
|
if (isFunction(arg)) {
|
|
46
42
|
arg = await arg()
|
|
47
|
-
}
|
|
43
|
+
}
|
|
44
|
+
if (isPlainObject(arg) && arg.knex) {
|
|
45
|
+
// A config object with a knex field was passed in, create a knex object
|
|
46
|
+
// from it to pass on to the execute function.
|
|
48
47
|
arg = Knex(arg.knex)
|
|
48
|
+
// Also add `knex.migrations` config as the first argument to `execute()`,
|
|
49
|
+
// so db:migrate & co. can receive migration configuration settings.
|
|
50
|
+
args.unshift(arg.knex.migrations || null)
|
|
49
51
|
}
|
|
50
52
|
const res = await execute(arg, ...args)
|
|
51
53
|
process.exit(res === true ? 0 : 1)
|
|
@@ -33,6 +33,7 @@ export class AdminController extends Controller {
|
|
|
33
33
|
this.mode = this.config.mode || (
|
|
34
34
|
this.app.config.env === 'development' ? 'development' : 'production'
|
|
35
35
|
)
|
|
36
|
+
this.closed = false
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
getPath(name) {
|
|
@@ -81,13 +82,21 @@ export class AdminController extends Controller {
|
|
|
81
82
|
// Shield admin views against unauthorized access.
|
|
82
83
|
const authorization = this.processAuthorize(this.authorize)
|
|
83
84
|
return async (ctx, next) => {
|
|
84
|
-
if (
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
if (this.closed) {
|
|
86
|
+
// Avoid strange behavior during shut-down of the vite dev server.
|
|
87
|
+
// Sending back a 408 response seems to work best, while a 503 sadly
|
|
88
|
+
// would put the client into a state that prevents the server from a
|
|
89
|
+
// proper shut-down, and a 205 would kill future hot-reloads.
|
|
90
|
+
ctx.status = 408 // Request Timeout
|
|
91
|
+
} else if (ctx.url === '/dito.js') {
|
|
92
|
+
// Don't call `next()`
|
|
93
|
+
this.sendDitoObject(ctx)
|
|
94
|
+
} else {
|
|
95
|
+
if (/\/views\b/.test(ctx.url)) {
|
|
96
|
+
await this.handleAuthorization(authorization, ctx)
|
|
97
|
+
}
|
|
98
|
+
await next()
|
|
89
99
|
}
|
|
90
|
-
await next()
|
|
91
100
|
}
|
|
92
101
|
}
|
|
93
102
|
|
|
@@ -131,7 +140,7 @@ export class AdminController extends Controller {
|
|
|
131
140
|
}
|
|
132
141
|
})
|
|
133
142
|
|
|
134
|
-
|
|
143
|
+
this.closed = false
|
|
135
144
|
|
|
136
145
|
// Monkey-patch `process.exit()` to filter out the calls caused by vite's
|
|
137
146
|
// handling of SIGTERM, see: https://github.com/vitejs/vite/issues/7627
|
|
@@ -140,22 +149,23 @@ export class AdminController extends Controller {
|
|
|
140
149
|
if (new Error().stack.includes('/vite/dist/')) {
|
|
141
150
|
// vite's own `exitProcess()` just called `process.exit(), and this
|
|
142
151
|
// means it has already called `server.close()` internally.
|
|
143
|
-
closed = true
|
|
152
|
+
this.closed = true
|
|
144
153
|
process.exit = exit
|
|
145
154
|
} else {
|
|
146
155
|
exit(code)
|
|
147
156
|
}
|
|
148
157
|
}
|
|
149
158
|
|
|
150
|
-
this.app.once('
|
|
159
|
+
this.app.once('after:stop', () => {
|
|
151
160
|
// For good timing it seems crucial to not add more ticks with async
|
|
152
161
|
// signature, so we directly return the `server.close()` promise instead.
|
|
153
162
|
process.exit = exit
|
|
154
|
-
if (!closed) {
|
|
155
|
-
closed = true
|
|
163
|
+
if (!this.closed) {
|
|
164
|
+
this.closed = true
|
|
156
165
|
return server.close()
|
|
157
166
|
}
|
|
158
167
|
})
|
|
168
|
+
|
|
159
169
|
this.koa.use(handleConnectMiddleware(server.middlewares, {
|
|
160
170
|
expandMountPath: true
|
|
161
171
|
}))
|