dx-server 0.10.0 → 0.10.1
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/README.md +6 -7
- package/cjs/body.d.ts +7 -7
- package/cjs/body.js +8 -8
- package/cjs/bodyHelpers.js +5 -5
- package/cjs/connect.d.ts +2 -2
- package/cjs/connect.js +4 -4
- package/cjs/dx.d.ts +1 -1
- package/cjs/dx.js +2 -2
- package/cjs/dxHelpers.d.ts +2 -2
- package/cjs/dxHelpers.js +6 -6
- package/cjs/express.d.ts +1 -1
- package/cjs/express.js +6 -6
- package/cjs/helpers.d.ts +2 -2
- package/cjs/helpers.js +10 -10
- package/cjs/index.d.ts +6 -6
- package/cjs/index.js +28 -28
- package/cjs/router.js +4 -4
- package/cjs/static.d.ts +2 -2
- package/cjs/static.js +6 -6
- package/cjs/staticHelpers.d.ts +1 -1
- package/cjs/staticHelpers.js +23 -23
- package/cjs/stream.d.ts +1 -1
- package/cjs/stream.js +1 -1
- package/cjs/vendors/mime.js +6 -6
- package/esm/body.d.ts +7 -7
- package/esm/body.js +2 -2
- package/esm/bodyHelpers.js +2 -2
- package/esm/connect.d.ts +2 -2
- package/esm/connect.js +2 -2
- package/esm/dx.d.ts +1 -1
- package/esm/dx.js +1 -1
- package/esm/dxHelpers.d.ts +2 -2
- package/esm/dxHelpers.js +3 -3
- package/esm/express.d.ts +1 -1
- package/esm/express.js +2 -2
- package/esm/helpers.d.ts +2 -2
- package/esm/helpers.js +2 -2
- package/esm/index.d.ts +6 -6
- package/esm/index.js +6 -6
- package/esm/router.js +2 -2
- package/esm/static.d.ts +2 -2
- package/esm/static.js +3 -3
- package/esm/staticHelpers.d.ts +1 -1
- package/esm/staticHelpers.js +7 -7
- package/esm/stream.d.ts +1 -1
- package/esm/stream.js +1 -1
- package/esm/vendors/mime.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,7 +138,6 @@ new Server().on('request', (req, res) => chain(
|
|
|
138
138
|
|
|
139
139
|
This example requires: `npm install express morgan helmet cors`
|
|
140
140
|
|
|
141
|
-
|
|
142
141
|
```javascript
|
|
143
142
|
import {Server} from 'node:http'
|
|
144
143
|
import {promisify} from 'node:util'
|
|
@@ -168,7 +167,7 @@ const authContext = makeDxContext(async () => {
|
|
|
168
167
|
if (getReq().headers.authorization) return {id: 1, name: 'joe (private)'}
|
|
169
168
|
})
|
|
170
169
|
|
|
171
|
-
|
|
170
|
+
function requireAuth() {
|
|
172
171
|
if (!authContext.value) throw new ServerError('Unauthorized', 401, 'UNAUTHORIZED')
|
|
173
172
|
}
|
|
174
173
|
|
|
@@ -427,9 +426,9 @@ router.get('/users/:id', ({matched}) => {
|
|
|
427
426
|
|
|
428
427
|
// Multiple routes
|
|
429
428
|
router.post({
|
|
430
|
-
'/api/users'
|
|
431
|
-
'/api/users/:id'
|
|
432
|
-
'/api/users/:id/posts'
|
|
429
|
+
'/api/users'() { /* create user */ },
|
|
430
|
+
'/api/users/:id'({matched}) { /* update user */ },
|
|
431
|
+
'/api/users/:id/posts'({matched}) { /* get user posts */ }
|
|
433
432
|
})
|
|
434
433
|
|
|
435
434
|
// All HTTP methods supported
|
|
@@ -509,7 +508,7 @@ import {
|
|
|
509
508
|
// Set global defaults
|
|
510
509
|
setBufferBodyDefaultOptions({
|
|
511
510
|
bodyLimit: 10 * 1024 * 1024, // 10MB
|
|
512
|
-
queryParser
|
|
511
|
+
queryParser(search){return myCustomParser(search)}
|
|
513
512
|
})
|
|
514
513
|
|
|
515
514
|
// Use directly with req/res (no context required)
|
|
@@ -618,7 +617,7 @@ const wss = new WebSocketServer({noServer: true})
|
|
|
618
617
|
|
|
619
618
|
server.on('upgrade', (request, socket, head) => {
|
|
620
619
|
if (request.url === '/ws') {
|
|
621
|
-
wss.handleUpgrade(request, socket, head,
|
|
620
|
+
wss.handleUpgrade(request, socket, head, ws => {
|
|
622
621
|
wss.emit('connection', ws, request)
|
|
623
622
|
})
|
|
624
623
|
}
|
package/cjs/body.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { type BufferBodyOptions } from './bodyHelpers.
|
|
3
|
-
export declare const getBuffer: import("./dx.
|
|
4
|
-
export declare const getJson: import("./dx.
|
|
5
|
-
export declare const getRaw: import("./dx.
|
|
6
|
-
export declare const getText: import("./dx.
|
|
7
|
-
export declare const getUrlEncoded: import("./dx.
|
|
8
|
-
export declare const getQuery: import("./dx.
|
|
2
|
+
import { type BufferBodyOptions } from './bodyHelpers.js';
|
|
3
|
+
export declare const getBuffer: import("./dx.js").Context<Buffer | undefined, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
4
|
+
export declare const getJson: import("./dx.js").Context<any, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
5
|
+
export declare const getRaw: import("./dx.js").Context<Buffer | undefined, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
6
|
+
export declare const getText: import("./dx.js").Context<string | undefined, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
7
|
+
export declare const getUrlEncoded: import("./dx.js").Context<any, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
8
|
+
export declare const getQuery: import("./dx.js").Context<any, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
package/cjs/body.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getQuery = exports.getUrlEncoded = exports.getText = exports.getRaw = exports.getJson = exports.getBuffer = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
exports.getBuffer = (0,
|
|
7
|
-
exports.getJson = (0,
|
|
8
|
-
exports.getRaw = (0,
|
|
9
|
-
exports.getText = (0,
|
|
10
|
-
exports.getUrlEncoded = (0,
|
|
11
|
-
exports.getQuery = (0,
|
|
4
|
+
const dx_js_1 = require("./dx.js");
|
|
5
|
+
const bodyHelpers_js_1 = require("./bodyHelpers.js");
|
|
6
|
+
exports.getBuffer = (0, dx_js_1.makeDxContext)((options) => (0, bodyHelpers_js_1.bufferFromReq)((0, dx_js_1.getReq)(), options));
|
|
7
|
+
exports.getJson = (0, dx_js_1.makeDxContext)((options) => (0, bodyHelpers_js_1.jsonFromReq)((0, dx_js_1.getReq)(), options));
|
|
8
|
+
exports.getRaw = (0, dx_js_1.makeDxContext)((options) => (0, bodyHelpers_js_1.rawFromReq)((0, dx_js_1.getReq)(), options));
|
|
9
|
+
exports.getText = (0, dx_js_1.makeDxContext)((options) => (0, bodyHelpers_js_1.textFromReq)((0, dx_js_1.getReq)(), options));
|
|
10
|
+
exports.getUrlEncoded = (0, dx_js_1.makeDxContext)((options) => (0, bodyHelpers_js_1.urlEncodedFromReq)((0, dx_js_1.getReq)(), options));
|
|
11
|
+
exports.getQuery = (0, dx_js_1.makeDxContext)((options) => (0, bodyHelpers_js_1.queryFromReq)((0, dx_js_1.getReq)(), options));
|
|
12
12
|
// to getFile use busboy
|
|
13
13
|
// https://github.com/mscdex/busboy
|
|
14
14
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm9keS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9ib2R5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLG1DQUE2QztBQUM3QyxxREFReUI7QUFFWixRQUFBLFNBQVMsR0FBRyxJQUFBLHFCQUFhLEVBQUMsQ0FBQyxPQUFvQyxFQUFFLEVBQUUsQ0FBQyxJQUFBLDhCQUFhLEVBQUMsSUFBQSxjQUFNLEdBQUUsRUFBRSxPQUFPLENBQUMsQ0FBQyxDQUFBO0FBQ3JHLFFBQUEsT0FBTyxHQUFHLElBQUEscUJBQWEsRUFBQyxDQUFDLE9BQW9DLEVBQUUsRUFBRSxDQUFDLElBQUEsNEJBQVcsRUFBQyxJQUFBLGNBQU0sR0FBRSxFQUFFLE9BQU8sQ0FBQyxDQUFDLENBQUE7QUFDakcsUUFBQSxNQUFNLEdBQUcsSUFBQSxxQkFBYSxFQUFDLENBQUMsT0FBb0MsRUFBRSxFQUFFLENBQUMsSUFBQSwyQkFBVSxFQUFDLElBQUEsY0FBTSxHQUFFLEVBQUUsT0FBTyxDQUFDLENBQUMsQ0FBQTtBQUMvRixRQUFBLE9BQU8sR0FBRyxJQUFBLHFCQUFhLEVBQUMsQ0FBQyxPQUFvQyxFQUFFLEVBQUUsQ0FBQyxJQUFBLDRCQUFXLEVBQUMsSUFBQSxjQUFNLEdBQUUsRUFBRSxPQUFPLENBQUMsQ0FBQyxDQUFBO0FBQ2pHLFFBQUEsYUFBYSxHQUFHLElBQUEscUJBQWEsRUFBQyxDQUFDLE9BQW9DLEVBQUUsRUFBRSxDQUFDLElBQUEsa0NBQWlCLEVBQUMsSUFBQSxjQUFNLEdBQUUsRUFBRSxPQUFPLENBQUMsQ0FBQyxDQUFBO0FBQzdHLFFBQUEsUUFBUSxHQUFHLElBQUEscUJBQWEsRUFBQyxDQUFDLE9BQW9DLEVBQUUsRUFBRSxDQUFDLElBQUEsNkJBQVksRUFBQyxJQUFBLGNBQU0sR0FBRSxFQUFFLE9BQU8sQ0FBQyxDQUFDLENBQUE7QUFFaEgsd0JBQXdCO0FBQ3hCLG1DQUFtQyJ9
|
package/cjs/bodyHelpers.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.queryFromReq = exports.urlFromReq = exports.urlEncodedFromReq = exports.textFromReq = exports.rawFromReq = exports.jsonFromReq = exports.bufferFromReq = exports.setBufferBodyDefaultOptions = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const stream_js_1 = require("./stream.js");
|
|
5
|
+
const contentType_js_1 = require("./vendors/contentType.js");
|
|
6
6
|
function defaultQueryParser(search) {
|
|
7
7
|
return Object.fromEntries(new URLSearchParams(search)); // support both leading ? and not
|
|
8
8
|
}
|
|
@@ -27,8 +27,8 @@ async function bufferFromReq(req, options) {
|
|
|
27
27
|
const contentLength = isNaN(contentLengthParsed) ? undefined : contentLengthParsed;
|
|
28
28
|
// read
|
|
29
29
|
const encoding = (req.headers['content-encoding'] ?? 'identity').toLowerCase();
|
|
30
|
-
const stream = (0,
|
|
31
|
-
return await (0,
|
|
30
|
+
const stream = (0, stream_js_1.getContentStream)(req, encoding);
|
|
31
|
+
return await (0, stream_js_1.readStream)(stream, {
|
|
32
32
|
length: encoding === 'identity' ? contentLength : undefined,
|
|
33
33
|
limit: bodyLimit,
|
|
34
34
|
});
|
|
@@ -39,7 +39,7 @@ function forceGetContentTypeParams(req, expected) {
|
|
|
39
39
|
const contentTypeRaw = req.headers['content-type'];
|
|
40
40
|
if (!contentTypeRaw)
|
|
41
41
|
return;
|
|
42
|
-
const { mediaType, parameters } = (0,
|
|
42
|
+
const { mediaType, parameters } = (0, contentType_js_1.parseContentType)(contentTypeRaw);
|
|
43
43
|
if (mediaType !== expected)
|
|
44
44
|
return;
|
|
45
45
|
return parameters;
|
package/cjs/connect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
-
import { type Chainable } from './dx.
|
|
4
|
-
import './polyfillWithResolvers.
|
|
3
|
+
import { type Chainable } from './dx.js';
|
|
4
|
+
import './polyfillWithResolvers.js';
|
|
5
5
|
export declare function connectMiddlewares(...middlewares: Array<(req: IncomingMessage, res: ServerResponse, next: () => any) => any>): Chainable;
|
package/cjs/connect.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.connectMiddlewares = void 0;
|
|
4
|
-
const
|
|
5
|
-
require("./polyfillWithResolvers.
|
|
4
|
+
const dx_js_1 = require("./dx.js");
|
|
5
|
+
require("./polyfillWithResolvers.js");
|
|
6
6
|
// support async middleware
|
|
7
7
|
// do not support error middleware (the one with 4 arguments)
|
|
8
8
|
function connectMiddlewares(...middlewares) {
|
|
9
9
|
return next => {
|
|
10
|
-
const req = (0,
|
|
11
|
-
const res = (0,
|
|
10
|
+
const req = (0, dx_js_1.getReq)();
|
|
11
|
+
const res = (0, dx_js_1.getRes)();
|
|
12
12
|
const defer = Promise.withResolvers();
|
|
13
13
|
// because middleware usually not return next() or await to next(),
|
|
14
14
|
// the next passed to the middleware must be resilient to error (never throw or reject)
|
package/cjs/dx.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/// <reference types="node" resolution-mode="require"/>
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
5
5
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
6
|
-
import type { SendOptions } from './staticHelpers.
|
|
6
|
+
import type { SendOptions } from './staticHelpers.js';
|
|
7
7
|
export interface Chainable<P extends any[] = any[], R = any, Next = (...np: any[]) => any> {
|
|
8
8
|
(next: Next, ...p: P): R;
|
|
9
9
|
}
|
package/cjs/dx.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setRedirect = exports.setJson = exports.setWebStream = exports.setNodeStream = exports.setBuffer = exports.setFile = exports.setHtml = exports.setEmpty = exports.setText = exports.getRes = exports.getReq = exports.dxServer = exports.makeDxContext = void 0;
|
|
4
4
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
|
-
const
|
|
5
|
+
const dxHelpers_js_1 = require("./dxHelpers.js");
|
|
6
6
|
function makeDxContext(maker) {
|
|
7
7
|
const promiseMap = new WeakMap();
|
|
8
8
|
const valueMap = new WeakMap();
|
|
@@ -42,7 +42,7 @@ function dxServer(req, res, options = {}) {
|
|
|
42
42
|
return async (next) => {
|
|
43
43
|
dxContext.set(req, { ...options });
|
|
44
44
|
const result = await requestStorage.run({ req, res }, next);
|
|
45
|
-
await (0,
|
|
45
|
+
await (0, dxHelpers_js_1.writeRes)(req, res, dxContext.get(req));
|
|
46
46
|
return result;
|
|
47
47
|
};
|
|
48
48
|
}
|
package/cjs/dxHelpers.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
/// <reference types="node" resolution-mode="require"/>
|
|
4
4
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
import { Readable } from 'node:stream';
|
|
6
|
-
import { type SendOptions } from './staticHelpers.
|
|
7
|
-
import './polyfillWithResolvers.
|
|
6
|
+
import { type SendOptions } from './staticHelpers.js';
|
|
7
|
+
import './polyfillWithResolvers.js';
|
|
8
8
|
export type DxContext = {
|
|
9
9
|
charset?: BufferEncoding;
|
|
10
10
|
jsonBeautify?: boolean;
|
package/cjs/dxHelpers.js
CHANGED
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.writeRes = void 0;
|
|
4
4
|
const node_stream_1 = require("node:stream");
|
|
5
5
|
const node_util_1 = require("node:util");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
require("./polyfillWithResolvers.
|
|
6
|
+
const etag_js_1 = require("./vendors/etag.js");
|
|
7
|
+
const staticHelpers_js_1 = require("./staticHelpers.js");
|
|
8
|
+
require("./polyfillWithResolvers.js");
|
|
9
9
|
async function writeRes(req, res, { type, data, charset, jsonBeautify, disableEtag, options }) {
|
|
10
10
|
const setContentType = (contentType) => {
|
|
11
11
|
if (res.headersSent || res.getHeader('content-type'))
|
|
@@ -45,7 +45,7 @@ async function writeRes(req, res, { type, data, charset, jsonBeautify, disableEt
|
|
|
45
45
|
break;
|
|
46
46
|
case 'file':
|
|
47
47
|
try {
|
|
48
|
-
await (0,
|
|
48
|
+
await (0, staticHelpers_js_1.sendFile)(req, res, data, options);
|
|
49
49
|
}
|
|
50
50
|
catch (e) {
|
|
51
51
|
// do nothing
|
|
@@ -95,10 +95,10 @@ async function writeRes(req, res, { type, data, charset, jsonBeautify, disableEt
|
|
|
95
95
|
// support: 304 (etag), zipping, file etag and last modified
|
|
96
96
|
res.setHeader('content-length', bufferOrStream.length);
|
|
97
97
|
if (!disableEtag) {
|
|
98
|
-
const etag = (0,
|
|
98
|
+
const etag = (0, etag_js_1.entityTag)(bufferOrStream);
|
|
99
99
|
const lastModified = res.getHeader('last-modified');
|
|
100
100
|
res.setHeader('ETag', etag);
|
|
101
|
-
if ((0,
|
|
101
|
+
if ((0, etag_js_1.isFreshETag)(req, etag)) {
|
|
102
102
|
res.removeHeader('content-type');
|
|
103
103
|
res.removeHeader('content-length');
|
|
104
104
|
res.removeHeader('transfer-encoding');
|
package/cjs/express.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Express, type Router } from 'express';
|
|
2
|
-
import './polyfillWithResolvers.
|
|
2
|
+
import './polyfillWithResolvers.js';
|
|
3
3
|
export declare function expressApp(setup: (app: Express) => any): Promise<(next: any) => Promise<void>>;
|
|
4
4
|
export declare function expressRouter(setup: (router: Router) => any): Promise<(next: any) => Promise<void>>;
|
package/cjs/express.js
CHANGED
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.expressRouter = exports.expressApp = void 0;
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const
|
|
9
|
-
require("./polyfillWithResolvers.
|
|
8
|
+
const dx_js_1 = require("./dx.js");
|
|
9
|
+
require("./polyfillWithResolvers.js");
|
|
10
10
|
async function expressApp(setup) {
|
|
11
11
|
const map = new WeakMap();
|
|
12
12
|
const app = (0, express_1.default)();
|
|
@@ -15,9 +15,9 @@ async function expressApp(setup) {
|
|
|
15
15
|
app.use((err, req, _res, _next) => map.get(req)?.reject(err));
|
|
16
16
|
return async (next) => {
|
|
17
17
|
const defer = Promise.withResolvers();
|
|
18
|
-
const req = (0,
|
|
18
|
+
const req = (0, dx_js_1.getReq)();
|
|
19
19
|
map.set(req, defer);
|
|
20
|
-
app(req, (0,
|
|
20
|
+
app(req, (0, dx_js_1.getRes)());
|
|
21
21
|
await defer.promise;
|
|
22
22
|
await next();
|
|
23
23
|
};
|
|
@@ -32,9 +32,9 @@ async function expressRouter(setup) {
|
|
|
32
32
|
router.use((err, req, _res, _next) => map.get(req)?.reject(err));
|
|
33
33
|
return async (next) => {
|
|
34
34
|
const defer = Promise.withResolvers();
|
|
35
|
-
const req = (0,
|
|
35
|
+
const req = (0, dx_js_1.getReq)();
|
|
36
36
|
map.set(req, defer);
|
|
37
|
-
router(req, (0,
|
|
37
|
+
router(req, (0, dx_js_1.getRes)());
|
|
38
38
|
await defer.promise; // if express middleware responses to the request, this will never resolve.
|
|
39
39
|
await next();
|
|
40
40
|
};
|
package/cjs/helpers.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { writeRes } from './dxHelpers.
|
|
2
|
-
export { setBufferBodyDefaultOptions, bufferFromReq, jsonFromReq, rawFromReq, textFromReq, urlEncodedFromReq, queryFromReq, } from './bodyHelpers.
|
|
1
|
+
export { writeRes } from './dxHelpers.js';
|
|
2
|
+
export { setBufferBodyDefaultOptions, bufferFromReq, jsonFromReq, rawFromReq, textFromReq, urlEncodedFromReq, queryFromReq, } from './bodyHelpers.js';
|
package/cjs/helpers.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.queryFromReq = exports.urlEncodedFromReq = exports.textFromReq = exports.rawFromReq = exports.jsonFromReq = exports.bufferFromReq = exports.setBufferBodyDefaultOptions = exports.writeRes = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "writeRes", { enumerable: true, get: function () { return
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "setBufferBodyDefaultOptions", { enumerable: true, get: function () { return
|
|
8
|
-
Object.defineProperty(exports, "bufferFromReq", { enumerable: true, get: function () { return
|
|
9
|
-
Object.defineProperty(exports, "jsonFromReq", { enumerable: true, get: function () { return
|
|
10
|
-
Object.defineProperty(exports, "rawFromReq", { enumerable: true, get: function () { return
|
|
11
|
-
Object.defineProperty(exports, "textFromReq", { enumerable: true, get: function () { return
|
|
12
|
-
Object.defineProperty(exports, "urlEncodedFromReq", { enumerable: true, get: function () { return
|
|
13
|
-
Object.defineProperty(exports, "queryFromReq", { enumerable: true, get: function () { return
|
|
4
|
+
var dxHelpers_js_1 = require("./dxHelpers.js");
|
|
5
|
+
Object.defineProperty(exports, "writeRes", { enumerable: true, get: function () { return dxHelpers_js_1.writeRes; } });
|
|
6
|
+
var bodyHelpers_js_1 = require("./bodyHelpers.js");
|
|
7
|
+
Object.defineProperty(exports, "setBufferBodyDefaultOptions", { enumerable: true, get: function () { return bodyHelpers_js_1.setBufferBodyDefaultOptions; } });
|
|
8
|
+
Object.defineProperty(exports, "bufferFromReq", { enumerable: true, get: function () { return bodyHelpers_js_1.bufferFromReq; } });
|
|
9
|
+
Object.defineProperty(exports, "jsonFromReq", { enumerable: true, get: function () { return bodyHelpers_js_1.jsonFromReq; } });
|
|
10
|
+
Object.defineProperty(exports, "rawFromReq", { enumerable: true, get: function () { return bodyHelpers_js_1.rawFromReq; } });
|
|
11
|
+
Object.defineProperty(exports, "textFromReq", { enumerable: true, get: function () { return bodyHelpers_js_1.textFromReq; } });
|
|
12
|
+
Object.defineProperty(exports, "urlEncodedFromReq", { enumerable: true, get: function () { return bodyHelpers_js_1.urlEncodedFromReq; } });
|
|
13
|
+
Object.defineProperty(exports, "queryFromReq", { enumerable: true, get: function () { return bodyHelpers_js_1.queryFromReq; } });
|
|
14
14
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLCtDQUF1QztBQUEvQix3R0FBQSxRQUFRLE9BQUE7QUFDaEIsbURBUXlCO0FBUHhCLDZIQUFBLDJCQUEyQixPQUFBO0FBQzNCLCtHQUFBLGFBQWEsT0FBQTtBQUNiLDZHQUFBLFdBQVcsT0FBQTtBQUNYLDRHQUFBLFVBQVUsT0FBQTtBQUNWLDZHQUFBLFdBQVcsT0FBQTtBQUNYLG1IQUFBLGlCQUFpQixPQUFBO0FBQ2pCLDhHQUFBLFlBQVksT0FBQSJ9
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { getReq, getRes, setHtml, setNodeStream, setWebStream, setJson, setBuffer, setRedirect, setText, setEmpty, setFile, makeDxContext, } from './dx.
|
|
2
|
-
import { dxServer } from './dx.
|
|
3
|
-
export { getBuffer, getJson, getRaw, getText, getUrlEncoded, getQuery, } from './body.
|
|
4
|
-
export { router } from './router.
|
|
5
|
-
export { connectMiddlewares } from './connect.
|
|
6
|
-
export { chainStatic } from './static.
|
|
1
|
+
export { getReq, getRes, setHtml, setNodeStream, setWebStream, setJson, setBuffer, setRedirect, setText, setEmpty, setFile, makeDxContext, } from './dx.js';
|
|
2
|
+
import { dxServer } from './dx.js';
|
|
3
|
+
export { getBuffer, getJson, getRaw, getText, getUrlEncoded, getQuery, } from './body.js';
|
|
4
|
+
export { router } from './router.js';
|
|
5
|
+
export { connectMiddlewares } from './connect.js';
|
|
6
|
+
export { chainStatic } from './static.js';
|
|
7
7
|
export default dxServer;
|
package/cjs/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.chainStatic = exports.connectMiddlewares = exports.router = exports.getQuery = exports.getUrlEncoded = exports.getText = exports.getRaw = exports.getJson = exports.getBuffer = exports.makeDxContext = exports.setFile = exports.setEmpty = exports.setText = exports.setRedirect = exports.setBuffer = exports.setJson = exports.setWebStream = exports.setNodeStream = exports.setHtml = exports.getRes = exports.getReq = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "getReq", { enumerable: true, get: function () { return
|
|
6
|
-
Object.defineProperty(exports, "getRes", { enumerable: true, get: function () { return
|
|
7
|
-
Object.defineProperty(exports, "setHtml", { enumerable: true, get: function () { return
|
|
8
|
-
Object.defineProperty(exports, "setNodeStream", { enumerable: true, get: function () { return
|
|
9
|
-
Object.defineProperty(exports, "setWebStream", { enumerable: true, get: function () { return
|
|
10
|
-
Object.defineProperty(exports, "setJson", { enumerable: true, get: function () { return
|
|
11
|
-
Object.defineProperty(exports, "setBuffer", { enumerable: true, get: function () { return
|
|
12
|
-
Object.defineProperty(exports, "setRedirect", { enumerable: true, get: function () { return
|
|
13
|
-
Object.defineProperty(exports, "setText", { enumerable: true, get: function () { return
|
|
14
|
-
Object.defineProperty(exports, "setEmpty", { enumerable: true, get: function () { return
|
|
15
|
-
Object.defineProperty(exports, "setFile", { enumerable: true, get: function () { return
|
|
16
|
-
Object.defineProperty(exports, "makeDxContext", { enumerable: true, get: function () { return
|
|
17
|
-
const
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "getBuffer", { enumerable: true, get: function () { return
|
|
20
|
-
Object.defineProperty(exports, "getJson", { enumerable: true, get: function () { return
|
|
21
|
-
Object.defineProperty(exports, "getRaw", { enumerable: true, get: function () { return
|
|
22
|
-
Object.defineProperty(exports, "getText", { enumerable: true, get: function () { return
|
|
23
|
-
Object.defineProperty(exports, "getUrlEncoded", { enumerable: true, get: function () { return
|
|
24
|
-
Object.defineProperty(exports, "getQuery", { enumerable: true, get: function () { return
|
|
25
|
-
var
|
|
26
|
-
Object.defineProperty(exports, "router", { enumerable: true, get: function () { return
|
|
27
|
-
var
|
|
28
|
-
Object.defineProperty(exports, "connectMiddlewares", { enumerable: true, get: function () { return
|
|
29
|
-
var
|
|
30
|
-
Object.defineProperty(exports, "chainStatic", { enumerable: true, get: function () { return
|
|
31
|
-
exports.default =
|
|
4
|
+
var dx_js_1 = require("./dx.js");
|
|
5
|
+
Object.defineProperty(exports, "getReq", { enumerable: true, get: function () { return dx_js_1.getReq; } });
|
|
6
|
+
Object.defineProperty(exports, "getRes", { enumerable: true, get: function () { return dx_js_1.getRes; } });
|
|
7
|
+
Object.defineProperty(exports, "setHtml", { enumerable: true, get: function () { return dx_js_1.setHtml; } });
|
|
8
|
+
Object.defineProperty(exports, "setNodeStream", { enumerable: true, get: function () { return dx_js_1.setNodeStream; } });
|
|
9
|
+
Object.defineProperty(exports, "setWebStream", { enumerable: true, get: function () { return dx_js_1.setWebStream; } });
|
|
10
|
+
Object.defineProperty(exports, "setJson", { enumerable: true, get: function () { return dx_js_1.setJson; } });
|
|
11
|
+
Object.defineProperty(exports, "setBuffer", { enumerable: true, get: function () { return dx_js_1.setBuffer; } });
|
|
12
|
+
Object.defineProperty(exports, "setRedirect", { enumerable: true, get: function () { return dx_js_1.setRedirect; } });
|
|
13
|
+
Object.defineProperty(exports, "setText", { enumerable: true, get: function () { return dx_js_1.setText; } });
|
|
14
|
+
Object.defineProperty(exports, "setEmpty", { enumerable: true, get: function () { return dx_js_1.setEmpty; } });
|
|
15
|
+
Object.defineProperty(exports, "setFile", { enumerable: true, get: function () { return dx_js_1.setFile; } });
|
|
16
|
+
Object.defineProperty(exports, "makeDxContext", { enumerable: true, get: function () { return dx_js_1.makeDxContext; } });
|
|
17
|
+
const dx_js_2 = require("./dx.js");
|
|
18
|
+
var body_js_1 = require("./body.js");
|
|
19
|
+
Object.defineProperty(exports, "getBuffer", { enumerable: true, get: function () { return body_js_1.getBuffer; } });
|
|
20
|
+
Object.defineProperty(exports, "getJson", { enumerable: true, get: function () { return body_js_1.getJson; } });
|
|
21
|
+
Object.defineProperty(exports, "getRaw", { enumerable: true, get: function () { return body_js_1.getRaw; } });
|
|
22
|
+
Object.defineProperty(exports, "getText", { enumerable: true, get: function () { return body_js_1.getText; } });
|
|
23
|
+
Object.defineProperty(exports, "getUrlEncoded", { enumerable: true, get: function () { return body_js_1.getUrlEncoded; } });
|
|
24
|
+
Object.defineProperty(exports, "getQuery", { enumerable: true, get: function () { return body_js_1.getQuery; } });
|
|
25
|
+
var router_js_1 = require("./router.js");
|
|
26
|
+
Object.defineProperty(exports, "router", { enumerable: true, get: function () { return router_js_1.router; } });
|
|
27
|
+
var connect_js_1 = require("./connect.js");
|
|
28
|
+
Object.defineProperty(exports, "connectMiddlewares", { enumerable: true, get: function () { return connect_js_1.connectMiddlewares; } });
|
|
29
|
+
var static_js_1 = require("./static.js");
|
|
30
|
+
Object.defineProperty(exports, "chainStatic", { enumerable: true, get: function () { return static_js_1.chainStatic; } });
|
|
31
|
+
exports.default = dx_js_2.dxServer;
|
|
32
32
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsaUNBYWdCO0FBWmYsK0ZBQUEsTUFBTSxPQUFBO0FBQ04sK0ZBQUEsTUFBTSxPQUFBO0FBQ04sZ0dBQUEsT0FBTyxPQUFBO0FBQ1Asc0dBQUEsYUFBYSxPQUFBO0FBQ2IscUdBQUEsWUFBWSxPQUFBO0FBQ1osZ0dBQUEsT0FBTyxPQUFBO0FBQ1Asa0dBQUEsU0FBUyxPQUFBO0FBQ1Qsb0dBQUEsV0FBVyxPQUFBO0FBQ1gsZ0dBQUEsT0FBTyxPQUFBO0FBQ1AsaUdBQUEsUUFBUSxPQUFBO0FBQ1IsZ0dBQUEsT0FBTyxPQUFBO0FBQ1Asc0dBQUEsYUFBYSxPQUFBO0FBRWQsbUNBQWdDO0FBQ2hDLHFDQU9rQjtBQU5qQixvR0FBQSxTQUFTLE9BQUE7QUFDVCxrR0FBQSxPQUFPLE9BQUE7QUFDUCxpR0FBQSxNQUFNLE9BQUE7QUFDTixrR0FBQSxPQUFPLE9BQUE7QUFDUCx3R0FBQSxhQUFhLE9BQUE7QUFDYixtR0FBQSxRQUFRLE9BQUE7QUFFVCx5Q0FBa0M7QUFBMUIsbUdBQUEsTUFBTSxPQUFBO0FBQ2QsMkNBQStDO0FBQXZDLGdIQUFBLGtCQUFrQixPQUFBO0FBQzFCLHlDQUF1QztBQUEvQix3R0FBQSxXQUFXLE9BQUE7QUFFbkIsa0JBQWUsZ0JBQVEsQ0FBQSJ9
|
package/cjs/router.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.router = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const dx_js_1 = require("./dx.js");
|
|
5
|
+
const bodyHelpers_js_1 = require("./bodyHelpers.js");
|
|
6
6
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
|
|
7
7
|
const allMethods = [
|
|
8
8
|
'get', 'head', 'post', 'put', 'delete', 'connect', 'options', 'trace', 'patch'
|
|
@@ -11,7 +11,7 @@ function makeRouter(method, // undefined means any method
|
|
|
11
11
|
routes, { prefix = '', ...options } = {}) {
|
|
12
12
|
const routeWithUrlPatterns = routes.map(([pattern, handler]) => [new URLPattern({ pathname: `${prefix}${pattern}` }), handler]);
|
|
13
13
|
return next => {
|
|
14
|
-
const req = (0,
|
|
14
|
+
const req = (0, dx_js_1.getReq)();
|
|
15
15
|
if (method !== undefined && req.method !== method.toUpperCase())
|
|
16
16
|
return next();
|
|
17
17
|
for (const [urlPattern, handler] of routeWithUrlPatterns) {
|
|
@@ -23,7 +23,7 @@ routes, { prefix = '', ...options } = {}) {
|
|
|
23
23
|
// to test: curl -X OPTIONS --request-target '*' http://localhost:3000 -D -
|
|
24
24
|
// req.url === '*'
|
|
25
25
|
// new URL('*', 'https://example.com').pathname === '/*'
|
|
26
|
-
const matched = urlPattern.exec({ pathname: (0,
|
|
26
|
+
const matched = urlPattern.exec({ pathname: (0, bodyHelpers_js_1.urlFromReq)(req).pathname });
|
|
27
27
|
if (matched)
|
|
28
28
|
return handler({ matched, next });
|
|
29
29
|
}
|
package/cjs/static.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Chainable } from './dx.
|
|
2
|
-
import type { SendOptions } from './staticHelpers.
|
|
1
|
+
import { type Chainable } from './dx.js';
|
|
2
|
+
import type { SendOptions } from './staticHelpers.js';
|
|
3
3
|
export declare function chainStatic(pattern: string, { getPathname, ...options }: SendOptions & {
|
|
4
4
|
getPathname?(matched: any): string;
|
|
5
5
|
}): Chainable;
|
package/cjs/static.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.chainStatic = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const dx_js_1 = require("./dx.js");
|
|
5
|
+
const staticHelpers_js_1 = require("./staticHelpers.js");
|
|
6
|
+
const bodyHelpers_js_1 = require("./bodyHelpers.js");
|
|
7
7
|
function chainStatic(pattern, { getPathname, ...options }) {
|
|
8
8
|
const urlPattern = new URLPattern({ pathname: pattern });
|
|
9
9
|
return async (next) => {
|
|
10
|
-
const req = (0,
|
|
10
|
+
const req = (0, dx_js_1.getReq)();
|
|
11
11
|
if (req.method !== 'GET' && req.method !== 'HEAD')
|
|
12
12
|
return next();
|
|
13
|
-
const { pathname } = (0,
|
|
13
|
+
const { pathname } = (0, bodyHelpers_js_1.urlFromReq)(req);
|
|
14
14
|
const matched = urlPattern.exec({ pathname });
|
|
15
15
|
if (!matched)
|
|
16
16
|
return next();
|
|
17
17
|
try {
|
|
18
|
-
await (0,
|
|
18
|
+
await (0, staticHelpers_js_1.sendFile)(req, (0, dx_js_1.getRes)(), getPathname?.(matched)
|
|
19
19
|
?? decodeURIComponent(pathname), options);
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
package/cjs/staticHelpers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
-
import './polyfillWithResolvers.
|
|
3
|
+
import './polyfillWithResolvers.js';
|
|
4
4
|
export interface SendOptions {
|
|
5
5
|
disableAcceptRanges?: boolean;
|
|
6
6
|
disableLastModified?: boolean;
|
package/cjs/staticHelpers.js
CHANGED
|
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.sendFile = void 0;
|
|
7
|
-
require("./polyfillWithResolvers.
|
|
8
|
-
const
|
|
7
|
+
require("./polyfillWithResolvers.js");
|
|
8
|
+
const dx_js_1 = require("./dx.js");
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const promises_1 = require("node:fs/promises");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
11
|
+
const etag_js_1 = require("./vendors/etag.js");
|
|
12
|
+
const mime_js_1 = require("./vendors/mime.js");
|
|
13
|
+
const fresh_js_1 = require("./vendors/fresh.js");
|
|
14
|
+
const rangeParser_js_1 = require("./vendors/rangeParser.js");
|
|
15
15
|
const node_fs_1 = require("node:fs");
|
|
16
|
-
const
|
|
16
|
+
const onFinished_js_1 = require("./vendors/onFinished.js");
|
|
17
17
|
const UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/;
|
|
18
18
|
const BYTES_RANGE_REGEXP = /^ *bytes=/;
|
|
19
19
|
async function sendFile(req, res, pathname, // plain path, not URI-encoded
|
|
@@ -21,14 +21,14 @@ async function sendFile(req, res, pathname, // plain path, not URI-encoded
|
|
|
21
21
|
immutable, } = {}) {
|
|
22
22
|
// null byte(s)
|
|
23
23
|
if (pathname.includes('\0'))
|
|
24
|
-
return (0,
|
|
24
|
+
return (0, dx_js_1.setHtml)('Invalid request', { status: 400 });
|
|
25
25
|
let parts;
|
|
26
26
|
if (root) {
|
|
27
27
|
// normalize
|
|
28
28
|
pathname = node_path_1.default.normalize(`.${node_path_1.default.sep}${pathname}`);
|
|
29
29
|
// malicious path
|
|
30
30
|
if (UP_PATH_REGEXP.test(pathname))
|
|
31
|
-
return (0,
|
|
31
|
+
return (0, dx_js_1.setHtml)('Forbidden', { status: 403 });
|
|
32
32
|
// explode path parts
|
|
33
33
|
parts = pathname.split(node_path_1.default.sep);
|
|
34
34
|
// join / normalize from optional root dir
|
|
@@ -37,7 +37,7 @@ immutable, } = {}) {
|
|
|
37
37
|
else {
|
|
38
38
|
// malicious path
|
|
39
39
|
if (UP_PATH_REGEXP.test(pathname))
|
|
40
|
-
return (0,
|
|
40
|
+
return (0, dx_js_1.setHtml)('Forbidden', { status: 403 });
|
|
41
41
|
// explode path parts
|
|
42
42
|
parts = node_path_1.default.normalize(pathname).split(node_path_1.default.sep);
|
|
43
43
|
// join / normalize from optional root dir
|
|
@@ -49,14 +49,14 @@ immutable, } = {}) {
|
|
|
49
49
|
case 'allow':
|
|
50
50
|
break;
|
|
51
51
|
case 'deny':
|
|
52
|
-
return (0,
|
|
52
|
+
return (0, dx_js_1.setHtml)('Forbidden', { status: 403 });
|
|
53
53
|
case 'ignore':
|
|
54
54
|
default:
|
|
55
55
|
throw new Error('Forbidden: dotfiles are not allowed');
|
|
56
56
|
}
|
|
57
57
|
// pathEndsWithSep
|
|
58
58
|
if (pathname[pathname.length - 1] === node_path_1.default.sep)
|
|
59
|
-
return (0,
|
|
59
|
+
return (0, dx_js_1.setHtml)('Forbidden: directory access is not allowed', { status: 403 });
|
|
60
60
|
const fileStat = await (0, promises_1.stat)(pathname);
|
|
61
61
|
// not found, check extensions
|
|
62
62
|
// if (err.code === 'ENOENT' && !path.extname(pathname) && !pathEndsWithSep) throw err
|
|
@@ -82,11 +82,11 @@ immutable, } = {}) {
|
|
|
82
82
|
if (!disableLastModified && !res.getHeader('Last-Modified'))
|
|
83
83
|
res.setHeader('Last-Modified', fileStat.mtime.toUTCString());
|
|
84
84
|
if (!disableEtag && !res.getHeader('ETag'))
|
|
85
|
-
res.setHeader('ETag', (0,
|
|
85
|
+
res.setHeader('ETag', (0, etag_js_1.statTag)(fileStat));
|
|
86
86
|
// #endregion
|
|
87
87
|
// content-type
|
|
88
88
|
if (!res.getHeader('Content-Type'))
|
|
89
|
-
res.setHeader('Content-Type', (0,
|
|
89
|
+
res.setHeader('Content-Type', (0, mime_js_1.contentTypeForExtension)(node_path_1.default.extname(pathname).slice(1)) || 'application/octet-stream');
|
|
90
90
|
// conditional GET support
|
|
91
91
|
// isConditionalGET
|
|
92
92
|
if (req.headers['if-match'] || req.headers['if-unmodified-since'] || req.headers['if-none-match'] || req.headers['if-modified-since']) {
|
|
@@ -96,13 +96,13 @@ immutable, } = {}) {
|
|
|
96
96
|
if (match) {
|
|
97
97
|
const etag = res.getHeader('ETag');
|
|
98
98
|
if (!etag
|
|
99
|
-
|| (match !== '*' && (0,
|
|
99
|
+
|| (match !== '*' && (0, fresh_js_1.parseTokenList)(match).every(match => match !== etag && match !== 'W/' + etag && 'W/' + match !== etag)))
|
|
100
100
|
throw new Error('Precondition Failed: request headers do not match the response');
|
|
101
101
|
}
|
|
102
102
|
// if-unmodified-since
|
|
103
|
-
const unmodifiedSince = (0,
|
|
103
|
+
const unmodifiedSince = (0, fresh_js_1.parseHttpDate)(req.headers['if-unmodified-since']);
|
|
104
104
|
if (!isNaN(unmodifiedSince)) {
|
|
105
|
-
const lastModified = (0,
|
|
105
|
+
const lastModified = (0, fresh_js_1.parseHttpDate)(res.getHeader('Last-Modified'));
|
|
106
106
|
if (isNaN(lastModified) || lastModified > unmodifiedSince)
|
|
107
107
|
throw new Error('Precondition Failed: resource has been modified since the specified date');
|
|
108
108
|
}
|
|
@@ -110,7 +110,7 @@ immutable, } = {}) {
|
|
|
110
110
|
// isCachable
|
|
111
111
|
if (((res.statusCode >= 200 && res.statusCode < 300) ||
|
|
112
112
|
res.statusCode === 304)
|
|
113
|
-
&& (0,
|
|
113
|
+
&& (0, fresh_js_1.fresh)(req.headers, {
|
|
114
114
|
etag: res.getHeader('ETag'),
|
|
115
115
|
'last-modified': res.getHeader('Last-Modified')
|
|
116
116
|
})) {
|
|
@@ -120,7 +120,7 @@ immutable, } = {}) {
|
|
|
120
120
|
res.removeHeader('Content-Length');
|
|
121
121
|
res.removeHeader('Content-Range');
|
|
122
122
|
res.removeHeader('Content-Type');
|
|
123
|
-
return (0,
|
|
123
|
+
return (0, dx_js_1.setEmpty)({ status: 304 });
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
// adjust len to start/end options
|
|
@@ -135,7 +135,7 @@ immutable, } = {}) {
|
|
|
135
135
|
let ranges = req.headers.range;
|
|
136
136
|
if (!disableAcceptRanges && BYTES_RANGE_REGEXP.test(ranges)) {
|
|
137
137
|
// parse
|
|
138
|
-
ranges = (0,
|
|
138
|
+
ranges = (0, rangeParser_js_1.parseRange)(len, ranges, { combine: true });
|
|
139
139
|
// If-Range support
|
|
140
140
|
if (!isRangeFresh(req, res))
|
|
141
141
|
ranges = -2;
|
|
@@ -165,12 +165,12 @@ immutable, } = {}) {
|
|
|
165
165
|
res.setHeader('Content-Length', len);
|
|
166
166
|
// HEAD support
|
|
167
167
|
if (req.method === 'HEAD')
|
|
168
|
-
return (0,
|
|
168
|
+
return (0, dx_js_1.setEmpty)();
|
|
169
169
|
// do stream
|
|
170
170
|
const stream = (0, node_fs_1.createReadStream)(pathname, { start, end });
|
|
171
171
|
stream.pipe(res);
|
|
172
172
|
const defer = Promise.withResolvers();
|
|
173
|
-
(0,
|
|
173
|
+
(0, onFinished_js_1.onFinished)(res, cleanup);
|
|
174
174
|
stream.on('error', err => {
|
|
175
175
|
cleanup();
|
|
176
176
|
defer.reject(err);
|
|
@@ -193,7 +193,7 @@ function isRangeFresh(req, res) {
|
|
|
193
193
|
}
|
|
194
194
|
// if-range as modified date
|
|
195
195
|
const lastModified = res.getHeader('Last-Modified');
|
|
196
|
-
return (0,
|
|
196
|
+
return (0, fresh_js_1.parseHttpDate)(lastModified) <= (0, fresh_js_1.parseHttpDate)(ifRange);
|
|
197
197
|
}
|
|
198
198
|
function contentRange(type, size, range) {
|
|
199
199
|
return `${type} ${range ? range.start + '-' + range.end : '*'}/${size}`;
|
package/cjs/stream.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/// <reference types="node" resolution-mode="require"/>
|
|
5
5
|
import type { IncomingMessage } from 'node:http';
|
|
6
6
|
import type { Readable } from 'node:stream';
|
|
7
|
-
import './polyfillWithResolvers.
|
|
7
|
+
import './polyfillWithResolvers.js';
|
|
8
8
|
export declare function getContentStream(req: IncomingMessage, encoding: string, disableInflate?: boolean): IncomingMessage | import("zlib").Gunzip;
|
|
9
9
|
export declare function readStream(stream: Readable, { length, limit }: {
|
|
10
10
|
length?: number;
|
package/cjs/stream.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readStream = exports.getContentStream = void 0;
|
|
4
4
|
const node_zlib_1 = require("node:zlib");
|
|
5
|
-
require("./polyfillWithResolvers.
|
|
5
|
+
require("./polyfillWithResolvers.js");
|
|
6
6
|
// note: there might be multiple encodings applied to the stream
|
|
7
7
|
// we only support one encoding
|
|
8
8
|
function getContentStream(req, encoding, disableInflate) {
|
package/cjs/vendors/mime.js
CHANGED
|
@@ -4,15 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.contentTypeForExtension = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const mimeDb_js_1 = __importDefault(require("./mimeDb.js"));
|
|
8
|
+
const mimeScore_js_1 = require("./mimeScore.js");
|
|
9
9
|
const extensionToMime = Object.create(null);
|
|
10
|
-
for (const [type, { extensions = [] }] of Object.entries(
|
|
10
|
+
for (const [type, { extensions = [] }] of Object.entries(mimeDb_js_1.default))
|
|
11
11
|
for (const extension of extensions)
|
|
12
12
|
extensionToMime[extension] = preferredType(extension, type, extensionToMime[extension]);
|
|
13
13
|
function preferredType(ext, type0, type1) {
|
|
14
|
-
const score0 = type0 ? (0,
|
|
15
|
-
const score1 = type1 ? (0,
|
|
14
|
+
const score0 = type0 ? (0, mimeScore_js_1.mimeScore)(type0, mimeDb_js_1.default[type0].source) : 0;
|
|
15
|
+
const score1 = type1 ? (0, mimeScore_js_1.mimeScore)(type1, mimeDb_js_1.default[type1].source) : 0;
|
|
16
16
|
return score0 > score1 ? type0 : type1;
|
|
17
17
|
}
|
|
18
18
|
function contentTypeForExtension(extension) {
|
|
@@ -32,7 +32,7 @@ const TEXT_TYPE_REGEXP = /^text\//i;
|
|
|
32
32
|
function determineCharset(type) {
|
|
33
33
|
// _TODO: use media-typer
|
|
34
34
|
const match = EXTRACT_TYPE_REGEXP.exec(type);
|
|
35
|
-
const mime = match &&
|
|
35
|
+
const mime = match && mimeDb_js_1.default[match[1].toLowerCase()];
|
|
36
36
|
if (mime?.charset)
|
|
37
37
|
return mime.charset;
|
|
38
38
|
// default text/* to utf-8
|
package/esm/body.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { type BufferBodyOptions } from './bodyHelpers.
|
|
3
|
-
export declare const getBuffer: import("./dx.
|
|
4
|
-
export declare const getJson: import("./dx.
|
|
5
|
-
export declare const getRaw: import("./dx.
|
|
6
|
-
export declare const getText: import("./dx.
|
|
7
|
-
export declare const getUrlEncoded: import("./dx.
|
|
8
|
-
export declare const getQuery: import("./dx.
|
|
2
|
+
import { type BufferBodyOptions } from './bodyHelpers.js';
|
|
3
|
+
export declare const getBuffer: import("./dx.js").Context<Buffer | undefined, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
4
|
+
export declare const getJson: import("./dx.js").Context<any, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
5
|
+
export declare const getRaw: import("./dx.js").Context<Buffer | undefined, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
6
|
+
export declare const getText: import("./dx.js").Context<string | undefined, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
7
|
+
export declare const getUrlEncoded: import("./dx.js").Context<any, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
|
8
|
+
export declare const getQuery: import("./dx.js").Context<any, [options?: Partial<BufferBodyOptions> | undefined], any, (...np: any[]) => any>;
|
package/esm/body.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getReq, makeDxContext } from './dx.
|
|
2
|
-
import { bufferFromReq, jsonFromReq, queryFromReq, rawFromReq, textFromReq, urlEncodedFromReq } from './bodyHelpers.
|
|
1
|
+
import { getReq, makeDxContext } from './dx.js';
|
|
2
|
+
import { bufferFromReq, jsonFromReq, queryFromReq, rawFromReq, textFromReq, urlEncodedFromReq } from './bodyHelpers.js';
|
|
3
3
|
export const getBuffer = makeDxContext((options) => bufferFromReq(getReq(), options));
|
|
4
4
|
export const getJson = makeDxContext((options) => jsonFromReq(getReq(), options));
|
|
5
5
|
export const getRaw = makeDxContext((options) => rawFromReq(getReq(), options));
|
package/esm/bodyHelpers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getContentStream, readStream } from './stream.
|
|
2
|
-
import { parseContentType } from './vendors/contentType.
|
|
1
|
+
import { getContentStream, readStream } from './stream.js';
|
|
2
|
+
import { parseContentType } from './vendors/contentType.js';
|
|
3
3
|
function defaultQueryParser(search) {
|
|
4
4
|
return Object.fromEntries(new URLSearchParams(search)); // support both leading ? and not
|
|
5
5
|
}
|
package/esm/connect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
-
import { type Chainable } from './dx.
|
|
4
|
-
import './polyfillWithResolvers.
|
|
3
|
+
import { type Chainable } from './dx.js';
|
|
4
|
+
import './polyfillWithResolvers.js';
|
|
5
5
|
export declare function connectMiddlewares(...middlewares: Array<(req: IncomingMessage, res: ServerResponse, next: () => any) => any>): Chainable;
|
package/esm/connect.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getReq, getRes } from './dx.
|
|
2
|
-
import './polyfillWithResolvers.
|
|
1
|
+
import { getReq, getRes } from './dx.js';
|
|
2
|
+
import './polyfillWithResolvers.js';
|
|
3
3
|
// support async middleware
|
|
4
4
|
// do not support error middleware (the one with 4 arguments)
|
|
5
5
|
export function connectMiddlewares(...middlewares) {
|
package/esm/dx.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/// <reference types="node" resolution-mode="require"/>
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
5
5
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
6
|
-
import type { SendOptions } from './staticHelpers.
|
|
6
|
+
import type { SendOptions } from './staticHelpers.js';
|
|
7
7
|
export interface Chainable<P extends any[] = any[], R = any, Next = (...np: any[]) => any> {
|
|
8
8
|
(next: Next, ...p: P): R;
|
|
9
9
|
}
|
package/esm/dx.js
CHANGED
package/esm/dxHelpers.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
/// <reference types="node" resolution-mode="require"/>
|
|
4
4
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
import { Readable } from 'node:stream';
|
|
6
|
-
import { type SendOptions } from './staticHelpers.
|
|
7
|
-
import './polyfillWithResolvers.
|
|
6
|
+
import { type SendOptions } from './staticHelpers.js';
|
|
7
|
+
import './polyfillWithResolvers.js';
|
|
8
8
|
export type DxContext = {
|
|
9
9
|
charset?: BufferEncoding;
|
|
10
10
|
jsonBeautify?: boolean;
|
package/esm/dxHelpers.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
-
import { entityTag, isFreshETag } from './vendors/etag.
|
|
4
|
-
import { sendFile } from './staticHelpers.
|
|
5
|
-
import './polyfillWithResolvers.
|
|
3
|
+
import { entityTag, isFreshETag } from './vendors/etag.js';
|
|
4
|
+
import { sendFile } from './staticHelpers.js';
|
|
5
|
+
import './polyfillWithResolvers.js';
|
|
6
6
|
export async function writeRes(req, res, { type, data, charset, jsonBeautify, disableEtag, options }) {
|
|
7
7
|
const setContentType = (contentType) => {
|
|
8
8
|
if (res.headersSent || res.getHeader('content-type'))
|
package/esm/express.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Express, type Router } from 'express';
|
|
2
|
-
import './polyfillWithResolvers.
|
|
2
|
+
import './polyfillWithResolvers.js';
|
|
3
3
|
export declare function expressApp(setup: (app: Express) => any): Promise<(next: any) => Promise<void>>;
|
|
4
4
|
export declare function expressRouter(setup: (router: Router) => any): Promise<(next: any) => Promise<void>>;
|
package/esm/express.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import { getReq, getRes } from './dx.
|
|
3
|
-
import './polyfillWithResolvers.
|
|
2
|
+
import { getReq, getRes } from './dx.js';
|
|
3
|
+
import './polyfillWithResolvers.js';
|
|
4
4
|
export async function expressApp(setup) {
|
|
5
5
|
const map = new WeakMap();
|
|
6
6
|
const app = express();
|
package/esm/helpers.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { writeRes } from './dxHelpers.
|
|
2
|
-
export { setBufferBodyDefaultOptions, bufferFromReq, jsonFromReq, rawFromReq, textFromReq, urlEncodedFromReq, queryFromReq, } from './bodyHelpers.
|
|
1
|
+
export { writeRes } from './dxHelpers.js';
|
|
2
|
+
export { setBufferBodyDefaultOptions, bufferFromReq, jsonFromReq, rawFromReq, textFromReq, urlEncodedFromReq, queryFromReq, } from './bodyHelpers.js';
|
package/esm/helpers.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { writeRes } from './dxHelpers.
|
|
2
|
-
export { setBufferBodyDefaultOptions, bufferFromReq, jsonFromReq, rawFromReq, textFromReq, urlEncodedFromReq, queryFromReq, } from './bodyHelpers.
|
|
1
|
+
export { writeRes } from './dxHelpers.js';
|
|
2
|
+
export { setBufferBodyDefaultOptions, bufferFromReq, jsonFromReq, rawFromReq, textFromReq, urlEncodedFromReq, queryFromReq, } from './bodyHelpers.js';
|
|
3
3
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBQyxRQUFRLEVBQUMsTUFBTSxnQkFBZ0IsQ0FBQTtBQUN2QyxPQUFPLEVBQ04sMkJBQTJCLEVBQzNCLGFBQWEsRUFDYixXQUFXLEVBQ1gsVUFBVSxFQUNWLFdBQVcsRUFDWCxpQkFBaUIsRUFDakIsWUFBWSxHQUNaLE1BQU0sa0JBQWtCLENBQUEifQ==
|
package/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { getReq, getRes, setHtml, setNodeStream, setWebStream, setJson, setBuffer, setRedirect, setText, setEmpty, setFile, makeDxContext, } from './dx.
|
|
2
|
-
import { dxServer } from './dx.
|
|
3
|
-
export { getBuffer, getJson, getRaw, getText, getUrlEncoded, getQuery, } from './body.
|
|
4
|
-
export { router } from './router.
|
|
5
|
-
export { connectMiddlewares } from './connect.
|
|
6
|
-
export { chainStatic } from './static.
|
|
1
|
+
export { getReq, getRes, setHtml, setNodeStream, setWebStream, setJson, setBuffer, setRedirect, setText, setEmpty, setFile, makeDxContext, } from './dx.js';
|
|
2
|
+
import { dxServer } from './dx.js';
|
|
3
|
+
export { getBuffer, getJson, getRaw, getText, getUrlEncoded, getQuery, } from './body.js';
|
|
4
|
+
export { router } from './router.js';
|
|
5
|
+
export { connectMiddlewares } from './connect.js';
|
|
6
|
+
export { chainStatic } from './static.js';
|
|
7
7
|
export default dxServer;
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { getReq, getRes, setHtml, setNodeStream, setWebStream, setJson, setBuffer, setRedirect, setText, setEmpty, setFile, makeDxContext, } from './dx.
|
|
2
|
-
import { dxServer } from './dx.
|
|
3
|
-
export { getBuffer, getJson, getRaw, getText, getUrlEncoded, getQuery, } from './body.
|
|
4
|
-
export { router } from './router.
|
|
5
|
-
export { connectMiddlewares } from './connect.
|
|
6
|
-
export { chainStatic } from './static.
|
|
1
|
+
export { getReq, getRes, setHtml, setNodeStream, setWebStream, setJson, setBuffer, setRedirect, setText, setEmpty, setFile, makeDxContext, } from './dx.js';
|
|
2
|
+
import { dxServer } from './dx.js';
|
|
3
|
+
export { getBuffer, getJson, getRaw, getText, getUrlEncoded, getQuery, } from './body.js';
|
|
4
|
+
export { router } from './router.js';
|
|
5
|
+
export { connectMiddlewares } from './connect.js';
|
|
6
|
+
export { chainStatic } from './static.js';
|
|
7
7
|
export default dxServer;
|
|
8
8
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUNOLE1BQU0sRUFDTixNQUFNLEVBQ04sT0FBTyxFQUNQLGFBQWEsRUFDYixZQUFZLEVBQ1osT0FBTyxFQUNQLFNBQVMsRUFDVCxXQUFXLEVBQ1gsT0FBTyxFQUNQLFFBQVEsRUFDUixPQUFPLEVBQ1AsYUFBYSxHQUNiLE1BQU0sU0FBUyxDQUFBO0FBQ2hCLE9BQU8sRUFBQyxRQUFRLEVBQUMsTUFBTSxTQUFTLENBQUE7QUFDaEMsT0FBTyxFQUNOLFNBQVMsRUFDVCxPQUFPLEVBQ1AsTUFBTSxFQUNOLE9BQU8sRUFDUCxhQUFhLEVBQ2IsUUFBUSxHQUNSLE1BQU0sV0FBVyxDQUFBO0FBQ2xCLE9BQU8sRUFBQyxNQUFNLEVBQUMsTUFBTSxhQUFhLENBQUE7QUFDbEMsT0FBTyxFQUFDLGtCQUFrQixFQUFDLE1BQU0sY0FBYyxDQUFBO0FBQy9DLE9BQU8sRUFBQyxXQUFXLEVBQUMsTUFBTSxhQUFhLENBQUE7QUFFdkMsZUFBZSxRQUFRLENBQUEifQ==
|
package/esm/router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getReq } from './dx.
|
|
2
|
-
import { urlFromReq } from './bodyHelpers.
|
|
1
|
+
import { getReq } from './dx.js';
|
|
2
|
+
import { urlFromReq } from './bodyHelpers.js';
|
|
3
3
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
|
|
4
4
|
const allMethods = [
|
|
5
5
|
'get', 'head', 'post', 'put', 'delete', 'connect', 'options', 'trace', 'patch'
|
package/esm/static.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Chainable } from './dx.
|
|
2
|
-
import type { SendOptions } from './staticHelpers.
|
|
1
|
+
import { type Chainable } from './dx.js';
|
|
2
|
+
import type { SendOptions } from './staticHelpers.js';
|
|
3
3
|
export declare function chainStatic(pattern: string, { getPathname, ...options }: SendOptions & {
|
|
4
4
|
getPathname?(matched: any): string;
|
|
5
5
|
}): Chainable;
|
package/esm/static.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getReq, getRes } from './dx.
|
|
2
|
-
import { sendFile } from './staticHelpers.
|
|
3
|
-
import { urlFromReq } from './bodyHelpers.
|
|
1
|
+
import { getReq, getRes } from './dx.js';
|
|
2
|
+
import { sendFile } from './staticHelpers.js';
|
|
3
|
+
import { urlFromReq } from './bodyHelpers.js';
|
|
4
4
|
export function chainStatic(pattern, { getPathname, ...options }) {
|
|
5
5
|
const urlPattern = new URLPattern({ pathname: pattern });
|
|
6
6
|
return async (next) => {
|
package/esm/staticHelpers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
-
import './polyfillWithResolvers.
|
|
3
|
+
import './polyfillWithResolvers.js';
|
|
4
4
|
export interface SendOptions {
|
|
5
5
|
disableAcceptRanges?: boolean;
|
|
6
6
|
disableLastModified?: boolean;
|
package/esm/staticHelpers.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import './polyfillWithResolvers.
|
|
2
|
-
import { setEmpty, setHtml } from './dx.
|
|
1
|
+
import './polyfillWithResolvers.js';
|
|
2
|
+
import { setEmpty, setHtml } from './dx.js';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { stat } from 'node:fs/promises';
|
|
5
|
-
import { statTag } from './vendors/etag.
|
|
6
|
-
import { contentTypeForExtension } from './vendors/mime.
|
|
7
|
-
import { fresh, parseHttpDate, parseTokenList } from './vendors/fresh.
|
|
8
|
-
import { parseRange } from './vendors/rangeParser.
|
|
5
|
+
import { statTag } from './vendors/etag.js';
|
|
6
|
+
import { contentTypeForExtension } from './vendors/mime.js';
|
|
7
|
+
import { fresh, parseHttpDate, parseTokenList } from './vendors/fresh.js';
|
|
8
|
+
import { parseRange } from './vendors/rangeParser.js';
|
|
9
9
|
import { createReadStream } from 'node:fs';
|
|
10
|
-
import { onFinished } from './vendors/onFinished.
|
|
10
|
+
import { onFinished } from './vendors/onFinished.js';
|
|
11
11
|
const UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/;
|
|
12
12
|
const BYTES_RANGE_REGEXP = /^ *bytes=/;
|
|
13
13
|
export async function sendFile(req, res, pathname, // plain path, not URI-encoded
|
package/esm/stream.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/// <reference types="node" resolution-mode="require"/>
|
|
5
5
|
import type { IncomingMessage } from 'node:http';
|
|
6
6
|
import type { Readable } from 'node:stream';
|
|
7
|
-
import './polyfillWithResolvers.
|
|
7
|
+
import './polyfillWithResolvers.js';
|
|
8
8
|
export declare function getContentStream(req: IncomingMessage, encoding: string, disableInflate?: boolean): IncomingMessage | import("zlib").Gunzip;
|
|
9
9
|
export declare function readStream(stream: Readable, { length, limit }: {
|
|
10
10
|
length?: number;
|
package/esm/stream.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createBrotliDecompress, createGunzip, createInflate } from 'node:zlib';
|
|
2
|
-
import './polyfillWithResolvers.
|
|
2
|
+
import './polyfillWithResolvers.js';
|
|
3
3
|
// note: there might be multiple encodings applied to the stream
|
|
4
4
|
// we only support one encoding
|
|
5
5
|
export function getContentStream(req, encoding, disableInflate) {
|
package/esm/vendors/mime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import mimeDb from './mimeDb.
|
|
2
|
-
import { mimeScore } from './mimeScore.
|
|
1
|
+
import mimeDb from './mimeDb.js';
|
|
2
|
+
import { mimeScore } from './mimeScore.js';
|
|
3
3
|
const extensionToMime = Object.create(null);
|
|
4
4
|
for (const [type, { extensions = [] }] of Object.entries(mimeDb))
|
|
5
5
|
for (const extension of extensions)
|