inertjs-core 1.0.0-beta.3 → 1.0.0-beta.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 +9 -2
- package/src/pipeline.js +19 -8
- package/src/server.js +1 -1
- package/test/server.test.js +1 -1
- package/test/stress.test.js +1 -1
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inertjs-core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"inertjs-optimizer": "^1.0.0-beta.
|
|
7
|
+
"inertjs-optimizer": "^1.0.0-beta.5",
|
|
8
|
+
"inertjs-vector": "^1.0.0-beta.5",
|
|
9
|
+
"inertjs-shield": "^1.0.0-beta.5",
|
|
10
|
+
"inertjs-router": "^1.0.0-beta.5"
|
|
8
11
|
},
|
|
9
12
|
"engines": {
|
|
10
13
|
"node": ">=22.0.0"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./src/index.js",
|
|
17
|
+
"./*": "./*"
|
|
11
18
|
}
|
|
12
19
|
}
|
package/src/pipeline.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
3
|
import { getScope } from './scope.js';
|
|
4
|
-
import { renderToStream } from '
|
|
5
|
-
import { raw } from '
|
|
6
|
-
import { getCspHeader, validateCsrfToken } from '
|
|
4
|
+
import { renderToStream } from 'inertjs-vector/src/stream.js';
|
|
5
|
+
import { raw } from 'inertjs-vector/src/index.js';
|
|
6
|
+
import { getCspHeader, validateCsrfToken } from 'inertjs-shield/src/index.js';
|
|
7
7
|
import { serveStatic } from './static.js';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import fs from 'node:fs/promises';
|
|
@@ -103,8 +103,10 @@ export async function handleRequest(req, res, config, trie) {
|
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
if (url.pathname.startsWith('/public/')) {
|
|
107
|
-
const filename = url.pathname.
|
|
106
|
+
if (url.pathname.startsWith('/public/') || url.pathname === '/favicon.ico' || url.pathname === '/robots.txt' || url.pathname === '/sitemap.xml' || url.pathname === '/site.webmanifest') {
|
|
107
|
+
const filename = url.pathname.startsWith('/public/')
|
|
108
|
+
? url.pathname.replace('/public/', '')
|
|
109
|
+
: url.pathname.slice(1);
|
|
108
110
|
// Need to detect content type based on extension
|
|
109
111
|
const ext = path.extname(filename).toLowerCase();
|
|
110
112
|
const contentTypes = {
|
|
@@ -114,7 +116,11 @@ export async function handleRequest(req, res, config, trie) {
|
|
|
114
116
|
'.svg': 'image/svg+xml',
|
|
115
117
|
'.css': 'text/css',
|
|
116
118
|
'.webp': 'image/webp',
|
|
117
|
-
'.ico': 'image/x-icon'
|
|
119
|
+
'.ico': 'image/x-icon',
|
|
120
|
+
'.txt': 'text/plain',
|
|
121
|
+
'.xml': 'application/xml',
|
|
122
|
+
'.webmanifest': 'application/manifest+json',
|
|
123
|
+
'.json': 'application/json'
|
|
118
124
|
};
|
|
119
125
|
const cType = contentTypes[ext] || 'application/octet-stream';
|
|
120
126
|
const filePath = path.resolve(process.cwd(), 'public', filename);
|
|
@@ -224,6 +230,11 @@ export async function handleRequest(req, res, config, trie) {
|
|
|
224
230
|
if (fluxModule.flux) {
|
|
225
231
|
data = await fluxModule.flux({ req, params, scope });
|
|
226
232
|
}
|
|
233
|
+
} else if (route.view) {
|
|
234
|
+
const viewModule = await import(pathToFileURL(route.view).href);
|
|
235
|
+
if (viewModule.flux) {
|
|
236
|
+
data = await viewModule.flux({ req, params, scope });
|
|
237
|
+
}
|
|
227
238
|
}
|
|
228
239
|
|
|
229
240
|
const isPulse = req.headers['accept']?.includes('application/vnd.inert.pulse+json');
|
|
@@ -253,7 +264,7 @@ export async function handleRequest(req, res, config, trie) {
|
|
|
253
264
|
let finalResult = viewResult;
|
|
254
265
|
|
|
255
266
|
if (isPulse) {
|
|
256
|
-
const { resolveToString } = await import('
|
|
267
|
+
const { resolveToString } = await import('inertjs-vector/src/index.js');
|
|
257
268
|
const viewHtml = await resolveToString(viewResult);
|
|
258
269
|
|
|
259
270
|
res.writeHead(200, {
|
|
@@ -285,7 +296,7 @@ export async function handleRequest(req, res, config, trie) {
|
|
|
285
296
|
|
|
286
297
|
// 6. Stream to response
|
|
287
298
|
if (isFlashMode && !isPulse && req.method === 'GET') {
|
|
288
|
-
const { resolveToString } = await import('
|
|
299
|
+
const { resolveToString } = await import('inertjs-vector/src/index.js');
|
|
289
300
|
const finalHtml = await resolveToString(finalResult);
|
|
290
301
|
// Cache it for the next request
|
|
291
302
|
flashCache.set(url.pathname, finalHtml);
|
package/src/server.js
CHANGED
|
@@ -3,7 +3,7 @@ import http2 from 'node:http2';
|
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import { requestScope } from './scope.js';
|
|
5
5
|
import { handleRequest } from './pipeline.js';
|
|
6
|
-
import { RateLimiter } from '
|
|
6
|
+
import { RateLimiter } from 'inertjs-shield/src/index.js';
|
|
7
7
|
|
|
8
8
|
export class CoreServer {
|
|
9
9
|
/**
|
package/test/server.test.js
CHANGED
|
@@ -6,7 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import os from 'node:os';
|
|
7
7
|
import { pathToFileURL } from 'node:url';
|
|
8
8
|
import { CoreServer } from '../src/server.js';
|
|
9
|
-
import { RouterTrie } from '
|
|
9
|
+
import { RouterTrie } from 'inertjs-router/src/trie.js';
|
|
10
10
|
|
|
11
11
|
function fetchH2C(url) {
|
|
12
12
|
return new Promise((resolve, reject) => {
|
package/test/stress.test.js
CHANGED
|
@@ -3,7 +3,7 @@ import assert from 'node:assert';
|
|
|
3
3
|
import http2 from 'node:http2';
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
5
|
import { CoreServer } from '../src/server.js';
|
|
6
|
-
import { RouterTrie } from '
|
|
6
|
+
import { RouterTrie } from 'inertjs-router/src/index.js';
|
|
7
7
|
|
|
8
8
|
test('CoreServer Rate Limiter E2E (100 reqs/sec limit)', async (t) => {
|
|
9
9
|
const trie = new RouterTrie();
|