feat: init
This commit is contained in:
101
node_modules/serve-placeholder/dist/index.cjs
generated
vendored
Normal file
101
node_modules/serve-placeholder/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
'use strict';
|
||||
|
||||
const defu = require('defu');
|
||||
|
||||
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
||||
|
||||
const defu__default = /*#__PURE__*/_interopDefaultCompat(defu);
|
||||
|
||||
const DefaultOptions = {
|
||||
statusCode: 404,
|
||||
skipUnknown: false,
|
||||
cacheHeaders: true,
|
||||
placeholderHeader: true,
|
||||
handlers: {
|
||||
// css
|
||||
".css": "css",
|
||||
// html
|
||||
".html": "html",
|
||||
".htm": "html",
|
||||
// image
|
||||
".png": "image",
|
||||
".jpg": "image",
|
||||
".jpeg": "image",
|
||||
".gif": "image",
|
||||
".svg": "image",
|
||||
".webp": "image",
|
||||
".bmp": "image",
|
||||
".ico": "image",
|
||||
// js
|
||||
".js": "js",
|
||||
// json
|
||||
".json": "json",
|
||||
// map
|
||||
".map": "map",
|
||||
// plain
|
||||
".txt": "plain",
|
||||
".text": "plain",
|
||||
".md": "plain"
|
||||
},
|
||||
placeholders: {
|
||||
css: "/* style not found */",
|
||||
default: void 0,
|
||||
html: "<!-- page not found -->",
|
||||
image: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
|
||||
js: "/* script not found */",
|
||||
json: "{}",
|
||||
map: '{"version": "3", "sources": [], "mappings": "" }',
|
||||
plain: ""
|
||||
},
|
||||
mimes: {
|
||||
css: "text/css",
|
||||
default: void 0,
|
||||
html: "text/html",
|
||||
js: "application/javascript",
|
||||
json: "application/json",
|
||||
image: "image/gif",
|
||||
map: "application/json",
|
||||
plain: "text/plain"
|
||||
}
|
||||
};
|
||||
|
||||
const EXT_REGEX = /\.[\dA-Za-z]+$/;
|
||||
function servePlaceholder(_options = {}) {
|
||||
const options = defu__default(_options, DefaultOptions);
|
||||
return function servePlaceholderMiddleware(req, res, next) {
|
||||
if (res.writableEnded) {
|
||||
return;
|
||||
}
|
||||
const url = req.url.split("?")[0];
|
||||
const ext = (url.match(EXT_REGEX) || [])[0] || "";
|
||||
let handler = options.handlers[ext];
|
||||
if (handler === false) {
|
||||
return next();
|
||||
}
|
||||
if (handler === void 0) {
|
||||
if (options.skipUnknown) {
|
||||
return next();
|
||||
}
|
||||
handler = "default";
|
||||
}
|
||||
if (options.statusCode) {
|
||||
res.statusCode = options.statusCode;
|
||||
}
|
||||
const mime = options.mimes[handler];
|
||||
if (mime) {
|
||||
res.setHeader("Content-Type", mime);
|
||||
}
|
||||
if (options.cacheHeaders) {
|
||||
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
res.setHeader("Pragma", "no-cache");
|
||||
res.setHeader("Expires", "0");
|
||||
}
|
||||
if (options.placeholderHeader) {
|
||||
res.setHeader("X-Placeholder", handler);
|
||||
}
|
||||
const placeholder = options.placeholders[handler];
|
||||
res.end(placeholder);
|
||||
};
|
||||
}
|
||||
|
||||
exports.servePlaceholder = servePlaceholder;
|
||||
47
node_modules/serve-placeholder/dist/index.d.cts
generated
vendored
Normal file
47
node_modules/serve-placeholder/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import { IncomingMessage, ServerResponse } from 'node:http';
|
||||
|
||||
interface ServePlaceholderOptions {
|
||||
/**
|
||||
* Sets `statusCode` for all handled responses. Set to `false` to disable overriding statusCode.
|
||||
*
|
||||
* @default 404
|
||||
*/
|
||||
statusCode?: number;
|
||||
/**
|
||||
* Skip middleware when no handler is defined for the current request.
|
||||
* Please note that if this option is set to `true`, then `default` handler will be disabled
|
||||
* @default false
|
||||
*/
|
||||
skipUnknown?: boolean;
|
||||
/**
|
||||
* Set headers to prevent accidentally caching 404 resources.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
cacheHeaders?: boolean;
|
||||
/**
|
||||
* Sets an `X-Placeholder` header with value of handler name.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
placeholderHeader?: boolean;
|
||||
/**
|
||||
* A mapping from file extensions to the handler. Extensions should start with *dot* like `.js`.
|
||||
* You can disable any of the handlers by setting the value to `null`
|
||||
* If the value of a handler is set to `false`, the middleware will be ignored for that extension.
|
||||
*/
|
||||
handlers?: Record<string, string | false>;
|
||||
/**
|
||||
* A mapping from handler to placeholder. Values can be `String` or `Buffer`. You can disable any of the placeholders by setting the value to `false`.
|
||||
*/
|
||||
placeholders?: Record<string, string | undefined>;
|
||||
/**
|
||||
* A mapping from handler to the mime type. Mime type will be set as `Content-Type` header. You can disable sending any of the mimes by setting the value to `false`.
|
||||
*/
|
||||
mimes?: Record<string, string | undefined>;
|
||||
}
|
||||
|
||||
type ServerMiddleware = (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
||||
declare function servePlaceholder(_options?: ServePlaceholderOptions): ServerMiddleware;
|
||||
|
||||
export { type ServerMiddleware, servePlaceholder };
|
||||
47
node_modules/serve-placeholder/dist/index.d.mts
generated
vendored
Normal file
47
node_modules/serve-placeholder/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import { IncomingMessage, ServerResponse } from 'node:http';
|
||||
|
||||
interface ServePlaceholderOptions {
|
||||
/**
|
||||
* Sets `statusCode` for all handled responses. Set to `false` to disable overriding statusCode.
|
||||
*
|
||||
* @default 404
|
||||
*/
|
||||
statusCode?: number;
|
||||
/**
|
||||
* Skip middleware when no handler is defined for the current request.
|
||||
* Please note that if this option is set to `true`, then `default` handler will be disabled
|
||||
* @default false
|
||||
*/
|
||||
skipUnknown?: boolean;
|
||||
/**
|
||||
* Set headers to prevent accidentally caching 404 resources.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
cacheHeaders?: boolean;
|
||||
/**
|
||||
* Sets an `X-Placeholder` header with value of handler name.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
placeholderHeader?: boolean;
|
||||
/**
|
||||
* A mapping from file extensions to the handler. Extensions should start with *dot* like `.js`.
|
||||
* You can disable any of the handlers by setting the value to `null`
|
||||
* If the value of a handler is set to `false`, the middleware will be ignored for that extension.
|
||||
*/
|
||||
handlers?: Record<string, string | false>;
|
||||
/**
|
||||
* A mapping from handler to placeholder. Values can be `String` or `Buffer`. You can disable any of the placeholders by setting the value to `false`.
|
||||
*/
|
||||
placeholders?: Record<string, string | undefined>;
|
||||
/**
|
||||
* A mapping from handler to the mime type. Mime type will be set as `Content-Type` header. You can disable sending any of the mimes by setting the value to `false`.
|
||||
*/
|
||||
mimes?: Record<string, string | undefined>;
|
||||
}
|
||||
|
||||
type ServerMiddleware = (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
||||
declare function servePlaceholder(_options?: ServePlaceholderOptions): ServerMiddleware;
|
||||
|
||||
export { type ServerMiddleware, servePlaceholder };
|
||||
47
node_modules/serve-placeholder/dist/index.d.ts
generated
vendored
Normal file
47
node_modules/serve-placeholder/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import { IncomingMessage, ServerResponse } from 'node:http';
|
||||
|
||||
interface ServePlaceholderOptions {
|
||||
/**
|
||||
* Sets `statusCode` for all handled responses. Set to `false` to disable overriding statusCode.
|
||||
*
|
||||
* @default 404
|
||||
*/
|
||||
statusCode?: number;
|
||||
/**
|
||||
* Skip middleware when no handler is defined for the current request.
|
||||
* Please note that if this option is set to `true`, then `default` handler will be disabled
|
||||
* @default false
|
||||
*/
|
||||
skipUnknown?: boolean;
|
||||
/**
|
||||
* Set headers to prevent accidentally caching 404 resources.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
cacheHeaders?: boolean;
|
||||
/**
|
||||
* Sets an `X-Placeholder` header with value of handler name.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
placeholderHeader?: boolean;
|
||||
/**
|
||||
* A mapping from file extensions to the handler. Extensions should start with *dot* like `.js`.
|
||||
* You can disable any of the handlers by setting the value to `null`
|
||||
* If the value of a handler is set to `false`, the middleware will be ignored for that extension.
|
||||
*/
|
||||
handlers?: Record<string, string | false>;
|
||||
/**
|
||||
* A mapping from handler to placeholder. Values can be `String` or `Buffer`. You can disable any of the placeholders by setting the value to `false`.
|
||||
*/
|
||||
placeholders?: Record<string, string | undefined>;
|
||||
/**
|
||||
* A mapping from handler to the mime type. Mime type will be set as `Content-Type` header. You can disable sending any of the mimes by setting the value to `false`.
|
||||
*/
|
||||
mimes?: Record<string, string | undefined>;
|
||||
}
|
||||
|
||||
type ServerMiddleware = (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
||||
declare function servePlaceholder(_options?: ServePlaceholderOptions): ServerMiddleware;
|
||||
|
||||
export { type ServerMiddleware, servePlaceholder };
|
||||
95
node_modules/serve-placeholder/dist/index.mjs
generated
vendored
Normal file
95
node_modules/serve-placeholder/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import defu from 'defu';
|
||||
|
||||
const DefaultOptions = {
|
||||
statusCode: 404,
|
||||
skipUnknown: false,
|
||||
cacheHeaders: true,
|
||||
placeholderHeader: true,
|
||||
handlers: {
|
||||
// css
|
||||
".css": "css",
|
||||
// html
|
||||
".html": "html",
|
||||
".htm": "html",
|
||||
// image
|
||||
".png": "image",
|
||||
".jpg": "image",
|
||||
".jpeg": "image",
|
||||
".gif": "image",
|
||||
".svg": "image",
|
||||
".webp": "image",
|
||||
".bmp": "image",
|
||||
".ico": "image",
|
||||
// js
|
||||
".js": "js",
|
||||
// json
|
||||
".json": "json",
|
||||
// map
|
||||
".map": "map",
|
||||
// plain
|
||||
".txt": "plain",
|
||||
".text": "plain",
|
||||
".md": "plain"
|
||||
},
|
||||
placeholders: {
|
||||
css: "/* style not found */",
|
||||
default: void 0,
|
||||
html: "<!-- page not found -->",
|
||||
image: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
|
||||
js: "/* script not found */",
|
||||
json: "{}",
|
||||
map: '{"version": "3", "sources": [], "mappings": "" }',
|
||||
plain: ""
|
||||
},
|
||||
mimes: {
|
||||
css: "text/css",
|
||||
default: void 0,
|
||||
html: "text/html",
|
||||
js: "application/javascript",
|
||||
json: "application/json",
|
||||
image: "image/gif",
|
||||
map: "application/json",
|
||||
plain: "text/plain"
|
||||
}
|
||||
};
|
||||
|
||||
const EXT_REGEX = /\.[\dA-Za-z]+$/;
|
||||
function servePlaceholder(_options = {}) {
|
||||
const options = defu(_options, DefaultOptions);
|
||||
return function servePlaceholderMiddleware(req, res, next) {
|
||||
if (res.writableEnded) {
|
||||
return;
|
||||
}
|
||||
const url = req.url.split("?")[0];
|
||||
const ext = (url.match(EXT_REGEX) || [])[0] || "";
|
||||
let handler = options.handlers[ext];
|
||||
if (handler === false) {
|
||||
return next();
|
||||
}
|
||||
if (handler === void 0) {
|
||||
if (options.skipUnknown) {
|
||||
return next();
|
||||
}
|
||||
handler = "default";
|
||||
}
|
||||
if (options.statusCode) {
|
||||
res.statusCode = options.statusCode;
|
||||
}
|
||||
const mime = options.mimes[handler];
|
||||
if (mime) {
|
||||
res.setHeader("Content-Type", mime);
|
||||
}
|
||||
if (options.cacheHeaders) {
|
||||
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
res.setHeader("Pragma", "no-cache");
|
||||
res.setHeader("Expires", "0");
|
||||
}
|
||||
if (options.placeholderHeader) {
|
||||
res.setHeader("X-Placeholder", handler);
|
||||
}
|
||||
const placeholder = options.placeholders[handler];
|
||||
res.end(placeholder);
|
||||
};
|
||||
}
|
||||
|
||||
export { servePlaceholder };
|
||||
Reference in New Issue
Block a user