@ditojs/server 1.5.3 → 1.5.6
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 +0 -2
- 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 +9 -6
- package/src/controllers/AdminController.js +21 -11
- package/src/middleware/index.js +0 -1
- package/src/middleware/ensureRunning.js +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditojs/server",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
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": "ab441bf2ebc4976288da803dcfe976c6cf40f997"
|
|
85
83
|
}
|
package/src/app/Application.js
CHANGED
|
@@ -42,7 +42,6 @@ import {
|
|
|
42
42
|
import {
|
|
43
43
|
attachLogger,
|
|
44
44
|
createTransaction,
|
|
45
|
-
ensureRunning,
|
|
46
45
|
findRoute,
|
|
47
46
|
handleError,
|
|
48
47
|
handleRoute,
|
|
@@ -508,7 +507,6 @@ export class Application extends Koa {
|
|
|
508
507
|
|
|
509
508
|
// Setup global middleware
|
|
510
509
|
|
|
511
|
-
this.use(ensureRunning(this))
|
|
512
510
|
this.use(attachLogger(this.logger))
|
|
513
511
|
if (app.responseTime !== false) {
|
|
514
512
|
this.use(responseTime(getOptions(app.responseTime)))
|
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,15 @@ async function execute() {
|
|
|
44
40
|
}
|
|
45
41
|
if (isFunction(arg)) {
|
|
46
42
|
arg = await arg()
|
|
47
|
-
}
|
|
48
|
-
|
|
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.
|
|
47
|
+
const knex = 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)
|
|
51
|
+
arg = knex
|
|
49
52
|
}
|
|
50
53
|
const res = await execute(arg, ...args)
|
|
51
54
|
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,18 +149,19 @@ 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
|
-
|
|
154
|
-
|
|
162
|
+
process.exit = exit
|
|
163
|
+
if (!this.closed) {
|
|
164
|
+
this.closed = true
|
|
155
165
|
return server.close()
|
|
156
166
|
}
|
|
157
167
|
})
|
package/src/middleware/index.js
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|