@zikojs/server 0.4.0 → 0.4.2
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 +3 -3
- package/src/middlewares/index.js +0 -1
- package/src/middlewares/trailingSlashMiddleware.js +5 -3
- package/src/server/index.js +13 -4
- package/src/server-only-utils/index.js +2 -1
- package/src/{middlewares/setupEnvironmentMiddleware.js → server-only-utils/setupEnvironment.js} +8 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zikojs/server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"type": "module",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@zikojs/express": "0.1.
|
|
36
|
-
"@zikojs/http": "0.1.
|
|
35
|
+
"@zikojs/express": "0.1.1",
|
|
36
|
+
"@zikojs/http": "0.1.1",
|
|
37
37
|
"compression": "^1.8.1",
|
|
38
38
|
"express": "^5.2.1",
|
|
39
39
|
"fast-glob": "^3.3.3",
|
package/src/middlewares/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const isProduction = process.env.NODE_ENV === 'production'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Handles trailing slashes based on the specified behavior strategy.
|
|
5
3
|
*
|
|
@@ -8,7 +6,11 @@ const isProduction = process.env.NODE_ENV === 'production'
|
|
|
8
6
|
* @param {import('http').ServerResponse} res
|
|
9
7
|
* @param {Function} next
|
|
10
8
|
*/
|
|
11
|
-
export function trailingSlashMiddleware(
|
|
9
|
+
export function trailingSlashMiddleware(
|
|
10
|
+
{
|
|
11
|
+
behavior,
|
|
12
|
+
isProduction
|
|
13
|
+
}, req, res, next) {
|
|
12
14
|
// 1. Skip middleware if behavior is 'ignore'
|
|
13
15
|
if (!behavior || behavior === 'ignore') {
|
|
14
16
|
return next()
|
package/src/server/index.js
CHANGED
|
@@ -4,10 +4,13 @@ import { pathToFileURL } from 'node:url' // <--- 1. Import pathToFileURL
|
|
|
4
4
|
import { httpAdapter } from '@zikojs/http'
|
|
5
5
|
import { expressAdapter } from '@zikojs/express'
|
|
6
6
|
import {
|
|
7
|
-
setupEnvironmentMiddleware,
|
|
8
7
|
trailingSlashMiddleware
|
|
9
8
|
} from '../middlewares/index.js'
|
|
10
9
|
|
|
10
|
+
import {
|
|
11
|
+
setupEnvironment
|
|
12
|
+
} from '../server-only-utils/index.js'
|
|
13
|
+
|
|
11
14
|
const isProduction = process.env.NODE_ENV === 'production'
|
|
12
15
|
|
|
13
16
|
export async function createServer({
|
|
@@ -33,15 +36,21 @@ export async function createServer({
|
|
|
33
36
|
|
|
34
37
|
// 4. Attach Trailing Slash Middleware
|
|
35
38
|
adapterInstance.use((req, res, next) => {
|
|
36
|
-
trailingSlashMiddleware(
|
|
39
|
+
trailingSlashMiddleware(
|
|
40
|
+
{
|
|
41
|
+
behavior : trailingSlash,
|
|
42
|
+
isProduction
|
|
43
|
+
},
|
|
44
|
+
req, res, next)
|
|
37
45
|
})
|
|
38
46
|
|
|
39
47
|
// 5. Setup environment middleware
|
|
40
|
-
const vite = await
|
|
48
|
+
const vite = await setupEnvironment({
|
|
41
49
|
adapterInstance,
|
|
42
50
|
rootDir,
|
|
43
51
|
urlBase,
|
|
44
|
-
clientDistPath
|
|
52
|
+
clientDistPath,
|
|
53
|
+
isProduction
|
|
45
54
|
})
|
|
46
55
|
|
|
47
56
|
// Cached production assets
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './globImports.js'
|
|
1
|
+
export * from './globImports.js'
|
|
2
|
+
export * from './setupEnvironment.js'
|
package/src/{middlewares/setupEnvironmentMiddleware.js → server-only-utils/setupEnvironment.js}
RENAMED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export async function setupEnvironment({
|
|
2
|
+
adapterInstance,
|
|
3
|
+
rootDir,
|
|
4
|
+
urlBase,
|
|
5
|
+
clientDistPath,
|
|
6
|
+
isProduction
|
|
7
|
+
}) {
|
|
8
|
+
if (!isProduction) {
|
|
7
9
|
const { createServer: createViteServer } = await import('vite')
|
|
8
10
|
const vite = await createViteServer({
|
|
9
11
|
root: rootDir,
|