Comparing version 0.6.5 to 0.7.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.router = void 0; | ||
exports.router = exports.matchPattern = void 0; | ||
const dx_js_1 = require("./dx.js"); | ||
@@ -20,2 +20,3 @@ require("urlpattern-polyfill"); | ||
} | ||
exports.matchPattern = matchPattern; | ||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods | ||
@@ -56,2 +57,2 @@ const allMethods = [ | ||
exports.router[method] = exports.router.method.bind(exports.router, method); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3JvdXRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxtQ0FBeUM7QUFFekMsK0JBQTRCO0FBQzVCLHFEQUEyQztBQU8zQyxxQkFBcUI7QUFDckIsZ0VBQWdFO0FBQ2hFLDBFQUEwRTtBQUMxRSwyRUFBMkU7QUFDM0UsU0FBUyxZQUFZLENBQ3BCLFFBQWdCLEVBQ2hCLE9BQWU7SUFHZixNQUFNLE9BQU8sR0FBRyxJQUFJLFVBQVUsQ0FBQyxFQUFDLFFBQVEsRUFBRSxPQUFPLEVBQUMsQ0FBQyxDQUFDLElBQUksQ0FBQyxFQUFDLFFBQVEsRUFBQyxDQUFDLENBQUE7SUFDcEUsSUFBSSxDQUFDLE9BQU87UUFBRSxPQUFNO0lBRXBCLE9BQU87UUFDTixPQUFPO1FBQ1AsTUFBTSxFQUFFLE9BQU8sQ0FBQyxRQUFRLENBQUMsTUFBZ0I7S0FDekMsQ0FBQTtBQUNGLENBQUM7QUFjRCw0REFBNEQ7QUFDNUQsTUFBTSxVQUFVLEdBQUc7SUFDbEIsS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLFFBQVEsRUFBRSxTQUFTLEVBQUUsU0FBUyxFQUFFL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FNLENBQUMsQ0FBQyxDQUFDLEVBQUUsTUFBTSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsRUFBRSxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUM7WUFDNUQsQ0FBQyxDQUFDLFVBQVUsQ0FBQyxTQUFTLEVBQUUsTUFBTSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUMsRUFBRSxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQTtJQUMvRCxDQUFDO0NBQ0QsQ0FBQTtBQUVELEtBQUssTUFBTSxNQUFNLElBQUksVUFBVTtJQUFFLGNBQU0sQ0FBQyxNQUFNLENBQUMsR0FBRyxjQUFNLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxjQUFNLEVBQUUsTUFBTSxDQUFDLENBQUEifQ== |
@@ -0,3 +1,7 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { Chainable } from './dx.js'; | ||
import { SendOptions } from 'send'; | ||
export declare function chainStatic(prefix: string, options: SendOptions): Chainable; | ||
import { IncomingMessage } from 'node:http'; | ||
export declare function chainStatic(pattern: string, { getPathname, ...options }: SendOptions & { | ||
getPathname?: (req: IncomingMessage) => string; | ||
}): Chainable; |
@@ -7,3 +7,4 @@ "use strict"; | ||
const staticHelpers_js_1 = require("./staticHelpers.js"); | ||
function chainStatic(prefix, options) { | ||
const router_js_1 = require("./router.js"); | ||
function chainStatic(pattern, { getPathname, ...options }) { | ||
return async (next) => { | ||
@@ -13,14 +14,7 @@ const req = (0, dx_js_1.getReq)(); | ||
return next(); | ||
if (!prefix.endsWith('/')) | ||
prefix += '/'; | ||
if (!prefix.startsWith('/')) | ||
prefix = '/' + prefix; | ||
const { pathname } = (0, bodyHelpers_js_1.urlFromReq)(req); | ||
if (!pathname.startsWith(prefix) | ||
&& !pathname.endsWith('/') | ||
&& pathname + '/' !== prefix) | ||
const match = (0, router_js_1.matchPattern)((0, bodyHelpers_js_1.urlFromReq)(req).pathname, pattern); | ||
if (!match) | ||
return next(); | ||
try { | ||
await (0, staticHelpers_js_1.sendFile)(req, (0, dx_js_1.getRes)(), pathname.slice(prefix.length - 1), // keep the trailing slash | ||
options, next); | ||
await (0, staticHelpers_js_1.sendFile)(req, (0, dx_js_1.getRes)(), getPathname?.(req) ?? (0, bodyHelpers_js_1.urlFromReq)(req).pathname, options, next); | ||
} | ||
@@ -35,2 +29,2 @@ catch (err) { | ||
exports.chainStatic = chainStatic; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGljLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3N0YXRpYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxtQ0FBaUQ7QUFFakQscURBQTJDO0FBQzNDLHlEQUEyQztBQUUzQyxTQUFnQixXQUFXLENBQzFCLE1BQWMsRUFDZCxPQUFvQjtJQUVwQixPQUFPLEtBQUssRUFBQyxJQUFJLEVBQUMsRUFBRTtRQUNuQixNQUFNLEdBQUcsR0FBRyxJQUFBLGNBQU0sR0FBRSxDQUFBO1FBQ3BCLElBQUksR0FBRyxDQUFDLE1BQU0sS0FBSyxLQUFLLElBQUksR0FBRyxDQUFDLE1BQU0sS0FBSyxNQUFNO1lBQUUsT0FBTyxJQUFJLEVBQUUsQ0FBQTtRQUVoRSxJQUFJLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxHQUFHLENBQUM7WUFBRSxNQUFNLElBQUksR0FBRyxDQUFBO1FBQ3hDLElBQUksQ0FBQyxNQUFNLENBQUMsVUFBVSxDQUFDLEdBQUcsQ0FBQztZQUFFLE1BQU0sR0FBRyxHQUFHLEdBQUcsTUFBTSxDQUFBO1FBRWxELE1BQU0sRUFBQyxRQUFRLEVBQUMsR0FBRyxJQUFBLDJCQUFVLEVBQUMsR0FBRyxDQUFDLENBQUE7UUFDbEMsSUFDQyx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yxNQUFNLEtBQUssS0FBSyxJQUFJLEdBQUcsQ0FBQyxNQUFNLEtBQUssTUFBTTtZQUFFLE9BQU8sSUFBSSxFQUFFLENBQUE7UUFFaEUsTUFBTSxLQUFLLEdBQUcsSUFBQSx3QkFBWSxFQUFDLElBQUEsMkJBQVUsRUFBQyxHQUFHLENBQUMsQ0FBQyxRQUFRLEVBQUUsT0FBTyxDQUFDLENBQUE7UUFDN0QsSUFBSSxDQUFDLEtBQUs7WUFBRSxPQUFPLElBQUksRUFBRSxDQUFBO1FBRXpCLElBQUksQ0FBQztZQUNKLE1BQU0sSUFBQSwyQkFBUSxFQUNkLEdBQUcsRUFDSCxJQUFBLGNBQU0sR0FBRSxFQUNSLFdBQVcsRUFBRSxDQUFDLEdBQUcsQ0FBQyxJQUFJLElBQUEsMkJBQVUsRUFBQyxHQUFHLENBQUMsQ0FBQyxRQUFRLEVBQzlDLE9BQU8sRUFDUCxJQUFJLENBQ0osQ0FBQTtRQUNELENBQUM7UUFBQyxPQUFPLEdBQUcsRUFBRSxDQUFDO1lBQ2QsT0FBTyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUE7WUFDaEIsMkNBQTJDO1lBQzNDLFlBQVk7UUFDYixDQUFDO0lBQ0YsQ0FBQyxDQUFBO0FBQ0YsQ0FBQztBQTVCRCxrQ0E0QkMifQ== |
@@ -8,3 +8,3 @@ import { getReq } from './dx.js'; | ||
// '/foo/' matches https://example.com/foo/ but not https://example.com/foo | ||
function matchPattern(pathname, pattern) { | ||
export function matchPattern(pathname, pattern) { | ||
const matched = new URLPattern({ pathname: pattern }).exec({ pathname }); | ||
@@ -53,2 +53,2 @@ if (!matched) | ||
router[method] = router.method.bind(router, method); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3JvdXRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdz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UFDO0NBQ0QsQ0FBQTtBQUVELEtBQUssTUFBTSxNQUFNLElBQUksVUFBVTtJQUFFLE1BQU0sQ0FBQyxNQUFNLENBQUMsR0FBRyxNQUFNLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxNQUFNLEVBQUUsTUFBTSxDQUFDLENBQUEifQ== |
@@ -0,3 +1,7 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { Chainable } from './dx.js'; | ||
import { SendOptions } from 'send'; | ||
export declare function chainStatic(prefix: string, options: SendOptions): Chainable; | ||
import { IncomingMessage } from 'node:http'; | ||
export declare function chainStatic(pattern: string, { getPathname, ...options }: SendOptions & { | ||
getPathname?: (req: IncomingMessage) => string; | ||
}): Chainable; |
import { getReq, getRes } from './dx.js'; | ||
import { urlFromReq } from './bodyHelpers.js'; | ||
import { sendFile } from './staticHelpers.js'; | ||
export function chainStatic(prefix, options) { | ||
import { matchPattern } from './router.js'; | ||
export function chainStatic(pattern, { getPathname, ...options }) { | ||
return async (next) => { | ||
@@ -9,14 +10,7 @@ const req = getReq(); | ||
return next(); | ||
if (!prefix.endsWith('/')) | ||
prefix += '/'; | ||
if (!prefix.startsWith('/')) | ||
prefix = '/' + prefix; | ||
const { pathname } = urlFromReq(req); | ||
if (!pathname.startsWith(prefix) | ||
&& !pathname.endsWith('/') | ||
&& pathname + '/' !== prefix) | ||
const match = matchPattern(urlFromReq(req).pathname, pattern); | ||
if (!match) | ||
return next(); | ||
try { | ||
await sendFile(req, getRes(), pathname.slice(prefix.length - 1), // keep the trailing slash | ||
options, next); | ||
await sendFile(req, getRes(), getPathname?.(req) ?? urlFromReq(req).pathname, options, next); | ||
} | ||
@@ -30,2 +24,2 @@ catch (err) { | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGljLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3N0YXRpYy50cyJdLCJuYW1lcyI6W10sI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QUcsQ0FBQyxDQUFDLFFBQVEsRUFBRSxPQUFPLENBQUMsQ0FBQTtRQUM3RCxJQUFJLENBQUMsS0FBSztZQUFFLE9BQU8sSUFBSSxFQUFFLENBQUE7UUFFekIsSUFBSSxDQUFDO1lBQ0osTUFBTSxRQUFRLENBQ2QsR0FBRyxFQUNILE1BQU0sRUFBRSxFQUNSLFdBQVcsRUFBRSxDQUFDLEdBQUcsQ0FBQyxJQUFJLFVBQVUsQ0FBQyxHQUFHLENBQUMsQ0FBQyxRQUFRLEVBQzlDLE9BQU8sRUFDUCxJQUFJLENBQ0osQ0FBQTtRQUNELENBQUM7UUFBQyxPQUFPLEdBQUcsRUFBRSxDQUFDO1lBQ2QsT0FBTyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUE7WUFDaEIsMkNBQTJDO1lBQzNDLFlBQVk7UUFDYixDQUFDO0lBQ0YsQ0FBQyxDQUFBO0FBQ0YsQ0FBQyJ9 |
{ | ||
"name": "dx-server", | ||
"version": "0.6.5", | ||
"version": "0.7.0", | ||
"main": "./cjs/index.js", | ||
@@ -39,4 +39,3 @@ "homepage": "https://github.com/tranvansang/dx-server", | ||
"urlpattern-polyfill": "^10.0.0" | ||
}, | ||
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
171611
65
1995