@celljs/serve-static 3.9.0 → 4.1.0
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/cell.yml +2 -2
- package/esm/node/embedded-assets.d.ts +20 -0
- package/esm/node/embedded-assets.js +76 -0
- package/esm/node/embedded-assets.js.map +1 -0
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/index.js.map +1 -1
- package/esm/node/serve-static-middleware.d.ts +22 -0
- package/esm/node/serve-static-middleware.js +75 -26
- package/esm/node/serve-static-middleware.js.map +1 -1
- package/esm/node/serve-static.d.ts +1 -1
- package/esm/node/serve-static.js +5 -4
- package/esm/node/serve-static.js.map +1 -1
- package/lib/node/embedded-assets.d.ts +21 -0
- package/lib/node/embedded-assets.d.ts.map +1 -0
- package/lib/node/embedded-assets.js +82 -0
- package/lib/node/embedded-assets.js.map +1 -0
- package/lib/node/embedded-assets.spec.d.ts +2 -0
- package/lib/node/embedded-assets.spec.d.ts.map +1 -0
- package/lib/node/embedded-assets.spec.js +60 -0
- package/lib/node/embedded-assets.spec.js.map +1 -0
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/serve-static-middleware.d.ts +22 -0
- package/lib/node/serve-static-middleware.d.ts.map +1 -1
- package/lib/node/serve-static-middleware.js +74 -25
- package/lib/node/serve-static-middleware.js.map +1 -1
- package/lib/node/serve-static-middleware.spec.d.ts +2 -0
- package/lib/node/serve-static-middleware.spec.d.ts.map +1 -0
- package/lib/node/serve-static-middleware.spec.js +232 -0
- package/lib/node/serve-static-middleware.spec.js.map +1 -0
- package/lib/node/serve-static.d.ts +1 -1
- package/lib/node/serve-static.d.ts.map +1 -1
- package/lib/node/serve-static.js +5 -4
- package/lib/node/serve-static.js.map +1 -1
- package/package.json +13 -15
- package/src/node/embedded-assets.spec.ts +67 -0
- package/src/node/embedded-assets.ts +82 -0
- package/src/node/index.ts +1 -0
- package/src/node/serve-static-middleware.spec.ts +284 -0
- package/src/node/serve-static-middleware.ts +85 -27
- package/src/node/serve-static.ts +5 -4
- package/cell-remote.yml +0 -3
- package/lib/hooks/webpack.d.ts +0 -4
- package/lib/hooks/webpack.d.ts.map +0 -1
- package/lib/hooks/webpack.js +0 -17
- package/lib/hooks/webpack.js.map +0 -1
- package/src/hooks/webpack.ts +0 -15
package/cell.yml
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ServeStaticOption } from './type.js';
|
|
2
|
+
/** A frontend file inside a server bundle built with `cell build --single`. */
|
|
3
|
+
export interface EmbeddedAsset {
|
|
4
|
+
/** Base64 of the content. */
|
|
5
|
+
body: string;
|
|
6
|
+
etag: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Frontend files that a `cell build --single` bundle registers before the application starts, by URL
|
|
10
|
+
* path (`/index.html`, `/assets/index-abc.js`). When they are there, they are served from memory
|
|
11
|
+
* instead of `cell.serve-static.root`.
|
|
12
|
+
*/
|
|
13
|
+
export declare namespace EmbeddedAssets {
|
|
14
|
+
const KEY: unique symbol;
|
|
15
|
+
function get(): Map<string, EmbeddedAsset> | undefined;
|
|
16
|
+
/** The counterpart of `serveStatic`: same options, same `next()` when a file is not there. */
|
|
17
|
+
function serve(assets: Map<string, EmbeddedAsset>, opts: ServeStaticOption & {
|
|
18
|
+
maxAge?: number;
|
|
19
|
+
}): (req: any, res: any, next: (err?: unknown) => void, url?: string) => void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import send from 'send';
|
|
2
|
+
/**
|
|
3
|
+
* Frontend files that a `cell build --single` bundle registers before the application starts, by URL
|
|
4
|
+
* path (`/index.html`, `/assets/index-abc.js`). When they are there, they are served from memory
|
|
5
|
+
* instead of `cell.serve-static.root`.
|
|
6
|
+
*/
|
|
7
|
+
export var EmbeddedAssets;
|
|
8
|
+
(function (EmbeddedAssets) {
|
|
9
|
+
EmbeddedAssets.KEY = Symbol.for('@celljs/serve-static/assets');
|
|
10
|
+
/** Decoded bodies, per table of assets: a table that is registered again is decoded again. */
|
|
11
|
+
const decoded = new WeakMap();
|
|
12
|
+
function get() {
|
|
13
|
+
return globalThis[EmbeddedAssets.KEY];
|
|
14
|
+
}
|
|
15
|
+
EmbeddedAssets.get = get;
|
|
16
|
+
function content(assets, path, asset) {
|
|
17
|
+
let bodies = decoded.get(assets);
|
|
18
|
+
if (!bodies) {
|
|
19
|
+
bodies = new Map();
|
|
20
|
+
decoded.set(assets, bodies);
|
|
21
|
+
}
|
|
22
|
+
let body = bodies.get(path);
|
|
23
|
+
if (!body) {
|
|
24
|
+
body = Buffer.from(asset.body, 'base64');
|
|
25
|
+
bodies.set(path, body);
|
|
26
|
+
}
|
|
27
|
+
return body;
|
|
28
|
+
}
|
|
29
|
+
/** The counterpart of `serveStatic`: same options, same `next()` when a file is not there. */
|
|
30
|
+
function serve(assets, opts) {
|
|
31
|
+
return (req, res, next, url = req.url) => {
|
|
32
|
+
var _a;
|
|
33
|
+
var _b, _c;
|
|
34
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
35
|
+
next();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let path;
|
|
39
|
+
try {
|
|
40
|
+
path = decodeURIComponent(new URL(url.replace(opts.baseHref, '/'), 'http://localhost').pathname);
|
|
41
|
+
}
|
|
42
|
+
catch (_d) {
|
|
43
|
+
next();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (path.endsWith('/')) {
|
|
47
|
+
path += 'index.html';
|
|
48
|
+
}
|
|
49
|
+
const asset = assets.get(path);
|
|
50
|
+
if (!asset) {
|
|
51
|
+
next();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const type = send.mime.lookup(path);
|
|
55
|
+
const charset = send.mime.charsets.lookup(type);
|
|
56
|
+
res.setHeader('Content-Type', charset ? `${type}; charset=${charset}` : type);
|
|
57
|
+
res.setHeader('ETag', asset.etag);
|
|
58
|
+
if (opts.cacheControl !== false) {
|
|
59
|
+
const maxAge = Math.floor(Math.min(Math.max(0, Number((_c = (_b = opts.maxAge) !== null && _b !== void 0 ? _b : opts.maxage) !== null && _c !== void 0 ? _c : 0)), 31536000000) / 1000);
|
|
60
|
+
res.setHeader('Cache-Control', `public, max-age=${maxAge}${opts.immutable ? ', immutable' : ''}`);
|
|
61
|
+
}
|
|
62
|
+
(_a = opts.setHeaders) === null || _a === void 0 ? void 0 : _a.call(opts, res, path, undefined);
|
|
63
|
+
if (req.headers['if-none-match'] === asset.etag) {
|
|
64
|
+
res.statusCode = 304;
|
|
65
|
+
res.end();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const body = content(assets, path, asset);
|
|
69
|
+
res.statusCode = 200;
|
|
70
|
+
res.setHeader('Content-Length', body.length);
|
|
71
|
+
res.end(req.method === 'HEAD' ? undefined : body);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
EmbeddedAssets.serve = serve;
|
|
75
|
+
})(EmbeddedAssets || (EmbeddedAssets = {}));
|
|
76
|
+
//# sourceMappingURL=embedded-assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded-assets.js","sourceRoot":"","sources":["../../src/node/embedded-assets.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAUxB;;;;GAIG;AACH,MAAM,KAAW,cAAc,CAkE9B;AAlED,WAAiB,cAAc;IACd,kBAAG,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAE7D,8FAA8F;IAC9F,MAAM,OAAO,GAAG,IAAI,OAAO,EAAmD,CAAC;IAE/E,SAAgB,GAAG;QACf,OAAQ,UAAqE,CAAC,kBAAG,CAAC,CAAC;IACvF,CAAC;IAFe,eAAA,GAAG,MAElB,CAAA;IAED,SAAS,OAAO,CAAC,MAAkC,EAAE,IAA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,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7C,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACtD,CAAC,CAAC;IACN,CAAC;IAxCe,eAAA,KAAK,QAwCpB,CAAA;AACL,CAAC,EAlEgB,cAAc,KAAd,cAAc,QAkE9B"}
|
package/esm/node/index.d.ts
CHANGED
package/esm/node/index.js
CHANGED
package/esm/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AACA,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AACA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Middleware, Context, RequestMatcher } from '@celljs/web/lib/node';
|
|
2
|
+
import { OutgoingMessage } from 'http';
|
|
3
|
+
import type { ServeStaticOption } from './type.js';
|
|
4
|
+
type Serve = (req: any, res: any, next: (err?: any) => void, url?: string) => void;
|
|
2
5
|
export declare class ServeStaticMiddleware implements Middleware {
|
|
3
6
|
protected config: {
|
|
4
7
|
spa: boolean;
|
|
@@ -9,6 +12,25 @@ export declare class ServeStaticMiddleware implements Middleware {
|
|
|
9
12
|
};
|
|
10
13
|
protected path: string;
|
|
11
14
|
protected readonly requestMatcher: RequestMatcher;
|
|
15
|
+
/**
|
|
16
|
+
* Whether there is a frontend to serve: embedded in the bundle (`--single`) or on disk. On
|
|
17
|
+
* Cloudflare Workers the platform serves the frontend and the worker has no copy.
|
|
18
|
+
*/
|
|
19
|
+
protected hasFrontend: boolean;
|
|
20
|
+
/** Options of the file server: a copy of `cell.serve-static.options`, which stays untouched. */
|
|
21
|
+
protected options: ServeStaticOption & Record<string, any>;
|
|
22
|
+
protected serve: Serve;
|
|
23
|
+
/**
|
|
24
|
+
* Sets up the file server once. Cloudflare Workers allow I/O (`existsSync`) only while a request is
|
|
25
|
+
* handled; the application, and with it this component, starts on the first request there.
|
|
26
|
+
*/
|
|
27
|
+
protected init(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Adds the configured `headers` to every file, and gives HTML files their own Cache-Control
|
|
30
|
+
* (`htmlMaxAge` in milliseconds, default 0) so that a new build of the page is picked up.
|
|
31
|
+
*/
|
|
32
|
+
protected createSetHeaders(headers: Record<string, string> | undefined, htmlMaxAge: unknown): (res: OutgoingMessage, path: string) => void;
|
|
12
33
|
handle(ctx: Context, next: () => Promise<void>): Promise<void>;
|
|
13
34
|
priority: number;
|
|
14
35
|
}
|
|
36
|
+
export {};
|
|
@@ -9,17 +9,55 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Middleware, RequestMatcher, HTTP_MIDDLEWARE_PRIORITY } from '@celljs/web/lib/node';
|
|
11
11
|
import { serveStatic, mime } from './serve-static.js';
|
|
12
|
-
import {
|
|
12
|
+
import { EmbeddedAssets } from './embedded-assets.js';
|
|
13
|
+
import { Value, Component, Autowired, PostConstruct } from '@celljs/core';
|
|
13
14
|
import { HttpMethod, MediaType, HttpHeaders } from '@celljs/http';
|
|
14
15
|
import { SERVER_PATH } from '@celljs/web';
|
|
16
|
+
import { existsSync } from 'fs';
|
|
17
|
+
const SPA_INDEX = '/index.html';
|
|
15
18
|
let ServeStaticMiddleware = class ServeStaticMiddleware {
|
|
16
19
|
constructor() {
|
|
17
20
|
this.priority = HTTP_MIDDLEWARE_PRIORITY + 500;
|
|
18
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Sets up the file server once. Cloudflare Workers allow I/O (`existsSync`) only while a request is
|
|
24
|
+
* handled; the application, and with it this component, starts on the first request there.
|
|
25
|
+
*/
|
|
26
|
+
init() {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
var _c;
|
|
29
|
+
const { headers, htmlMaxAge, ...options } = (_a = this.config.options) !== null && _a !== void 0 ? _a : {};
|
|
30
|
+
this.options = { ...options, baseHref: this.path };
|
|
31
|
+
(_b = (_c = this.options).setHeaders) !== null && _b !== void 0 ? _b : (_c.setHeaders = this.createSetHeaders(headers, htmlMaxAge));
|
|
32
|
+
const embedded = EmbeddedAssets.get();
|
|
33
|
+
const root = this.config.root;
|
|
34
|
+
// No frontend (no `paths.public`, or nothing built there): every request goes on to the chain.
|
|
35
|
+
this.hasFrontend = !!embedded || (typeof root === 'string' && existsSync(root));
|
|
36
|
+
if (embedded) {
|
|
37
|
+
this.serve = EmbeddedAssets.serve(embedded, this.options);
|
|
38
|
+
}
|
|
39
|
+
else if (this.hasFrontend) {
|
|
40
|
+
this.serve = serveStatic(root, this.options);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Adds the configured `headers` to every file, and gives HTML files their own Cache-Control
|
|
45
|
+
* (`htmlMaxAge` in milliseconds, default 0) so that a new build of the page is picked up.
|
|
46
|
+
*/
|
|
47
|
+
createSetHeaders(headers, htmlMaxAge) {
|
|
48
|
+
const htmlCacheControl = `public, max-age=${Math.floor(Math.max(0, Number(htmlMaxAge !== null && htmlMaxAge !== void 0 ? htmlMaxAge : 0) || 0) / 1000)}`;
|
|
49
|
+
return (res, path) => {
|
|
50
|
+
if (headers) {
|
|
51
|
+
Object.keys(headers).forEach(key => res.setHeader(key, headers[key]));
|
|
52
|
+
}
|
|
53
|
+
if (mime.lookup(path) === MediaType.TEXT_HTML) {
|
|
54
|
+
res.setHeader(HttpHeaders.CACHE_CONTROL, htmlCacheControl);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
19
58
|
async handle(ctx, next) {
|
|
20
|
-
this.config.options.baseHref = this.path;
|
|
21
59
|
const method = ctx.request.method;
|
|
22
|
-
if (!(method === HttpMethod.GET || method === HttpMethod.HEAD) || ctx.request.query['static'] === 'skip') {
|
|
60
|
+
if (!this.hasFrontend || !(method === HttpMethod.GET || method === HttpMethod.HEAD) || ctx.request.query['static'] === 'skip') {
|
|
23
61
|
await next();
|
|
24
62
|
return;
|
|
25
63
|
}
|
|
@@ -31,38 +69,43 @@ let ServeStaticMiddleware = class ServeStaticMiddleware {
|
|
|
31
69
|
await next();
|
|
32
70
|
return;
|
|
33
71
|
}
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
const response = ctx.response;
|
|
74
|
+
// A file that is sent ends the response without calling back: the request is done then.
|
|
75
|
+
const done = () => {
|
|
76
|
+
stopWaiting();
|
|
77
|
+
resolve();
|
|
78
|
+
};
|
|
79
|
+
const stopWaiting = () => {
|
|
80
|
+
response.off('finish', done);
|
|
81
|
+
response.off('close', done);
|
|
82
|
+
};
|
|
83
|
+
// The rest of the chain answers instead: its outcome is this middleware's outcome.
|
|
84
|
+
const passOn = () => {
|
|
85
|
+
stopWaiting();
|
|
86
|
+
next().then(resolve, reject);
|
|
87
|
+
};
|
|
88
|
+
response.once('finish', done);
|
|
89
|
+
response.once('close', done);
|
|
90
|
+
// The SPA fallback serves /index.html for the request without changing request.url.
|
|
91
|
+
const attempt = (url) => this.serve(ctx.request, response, (err) => {
|
|
92
|
+
if (url !== SPA_INDEX) {
|
|
50
93
|
if (!this.config.spa) {
|
|
51
|
-
|
|
94
|
+
passOn();
|
|
52
95
|
return;
|
|
53
96
|
}
|
|
54
|
-
|
|
55
|
-
executor(resolve, reject);
|
|
97
|
+
attempt(SPA_INDEX);
|
|
56
98
|
}
|
|
57
99
|
else if (err) {
|
|
100
|
+
stopWaiting();
|
|
58
101
|
reject(err);
|
|
59
102
|
}
|
|
60
103
|
else {
|
|
61
|
-
|
|
104
|
+
passOn();
|
|
62
105
|
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
|
|
106
|
+
}, url);
|
|
107
|
+
attempt(ctx.request.url);
|
|
108
|
+
});
|
|
66
109
|
}
|
|
67
110
|
};
|
|
68
111
|
__decorate([
|
|
@@ -77,6 +120,12 @@ __decorate([
|
|
|
77
120
|
Autowired(RequestMatcher),
|
|
78
121
|
__metadata("design:type", Object)
|
|
79
122
|
], ServeStaticMiddleware.prototype, "requestMatcher", void 0);
|
|
123
|
+
__decorate([
|
|
124
|
+
PostConstruct(),
|
|
125
|
+
__metadata("design:type", Function),
|
|
126
|
+
__metadata("design:paramtypes", []),
|
|
127
|
+
__metadata("design:returntype", void 0)
|
|
128
|
+
], ServeStaticMiddleware.prototype, "init", null);
|
|
80
129
|
ServeStaticMiddleware = __decorate([
|
|
81
130
|
Component(Middleware)
|
|
82
131
|
], ServeStaticMiddleware);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve-static-middleware.js","sourceRoot":"","sources":["../../src/node/serve-static-middleware.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAW,cAAc,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrG,OAAO,EAAC,WAAW,EAAE,IAAI,EAAC,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"serve-static-middleware.js","sourceRoot":"","sources":["../../src/node/serve-static-middleware.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAW,cA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AAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAS,EAAE,EAAE;gBAC7E,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;oBACpB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;wBACnB,MAAM,EAAE,CAAC;wBACT,OAAO;oBACX,CAAC;oBACD,OAAO,CAAC,SAAS,CAAC,CAAC;gBACvB,CAAC;qBAAM,IAAI,GAAG,EAAE,CAAC;oBACb,WAAW,EAAE,CAAC;oBACd,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,CAAC;qBAAM,CAAC;oBACJ,MAAM,EAAE,CAAC;gBACb,CAAC;YACL,CAAC,EAAE,GAAG,CAAC,CAAC;YACR,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC;CAGJ,CAAA;AAhHa;IADT,KAAK,CAAC,sBAAsB,CAAC;;qDAC+D;AAGnF;IADT,KAAK,CAAC,WAAW,CAAC;;mDACI;AAGJ;IADlB,SAAS,CAAC,cAAc,CAAC;;6DACwB;AAkBxC;IADT,aAAa,EAAE;;;;iDAcf;AAxCQ,qBAAqB;IADjC,SAAS,CAAC,UAAU,CAAC;GACT,qBAAqB,CAmHjC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ServeStaticOption } from './type.js';
|
|
2
|
-
export declare const serveStatic: (root: string, opts: ServeStaticOption) => (req: any, res: any, next: Function) => any;
|
|
2
|
+
export declare const serveStatic: (root: string, opts: ServeStaticOption) => (req: any, res: any, next: Function, url?: string) => any;
|
|
3
3
|
export declare const mime: typeof import("mime");
|
package/esm/node/serve-static.js
CHANGED
|
@@ -7,7 +7,8 @@ export const serveStatic = (root, opts) => {
|
|
|
7
7
|
createRedirectDirectoryListener :
|
|
8
8
|
createNotFoundDirectoryListener;
|
|
9
9
|
opts.root = resolve(root);
|
|
10
|
-
|
|
10
|
+
/** `url` (default `req.url`) is what to serve; the SPA fallback passes `/index.html` without changing the request. */
|
|
11
|
+
return (req, res, next, url = req.url) => {
|
|
11
12
|
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
12
13
|
if (fallthrough) {
|
|
13
14
|
return next();
|
|
@@ -21,9 +22,9 @@ export const serveStatic = (root, opts) => {
|
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
24
|
let forwardError = !fallthrough;
|
|
24
|
-
const
|
|
25
|
-
const stream = send(req,
|
|
26
|
-
stream.on('directory', onDirectory(
|
|
25
|
+
const target = new URL(`${url.replace(baseHref, '/')}`, `http://${req.headers.host}`);
|
|
26
|
+
const stream = send(req, target.pathname, opts);
|
|
27
|
+
stream.on('directory', onDirectory(target));
|
|
27
28
|
if (setHeaders) {
|
|
28
29
|
stream.on('headers', setHeaders);
|
|
29
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve-static.js","sourceRoot":"","sources":["../../src/node/serve-static.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,sDAAsD;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,IAAuB,EAAE,EAAE;IAEjE,MAAM,EAAE,WAAW,GAAG,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACpE,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC;QAC1B,+BAA+B,CAAC,CAAC;QACjC,+BAA+B,CAAC;IAEpC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B,OAAO,CAAC,GAAQ,EAAE,GAAQ,EAAE,IAAc,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"serve-static.js","sourceRoot":"","sources":["../../src/node/serve-static.ts"],"names":[],"mappings":"AACA,O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;gBACjF,GAAG,GAAG,MAAM,CAAC,CAAC;YAElB,yBAAyB;YACzB,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,0BAA0B,CAAC,CAAC;YAC1D,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YACxD,GAAG,CAAC,SAAS,CAAC,yBAAyB,EAAE,sBAAsB,CAAC,CAAC;YACjE,GAAG,CAAC,SAAS,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;YACnD,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;YAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC,CAAC;IACN,CAAC;IAED,SAAS,kBAAkB,CAAC,KAAa,EAAE,IAAY;QACnD,OAAO,mBAAmB;YACtB,oBAAoB;YACpB,UAAU;YACV,0BAA0B;YAC1B,SAAS,GAAG,KAAK,GAAG,YAAY;YAChC,WAAW;YACX,UAAU;YACV,OAAO,GAAG,IAAI,GAAG,UAAU;YAC3B,WAAW;YACX,WAAW,CAAC;IACpB,CAAC;AAEL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ServeStaticOption } from './type';
|
|
2
|
+
/** A frontend file inside a server bundle built with `cell build --single`. */
|
|
3
|
+
export interface EmbeddedAsset {
|
|
4
|
+
/** Base64 of the content. */
|
|
5
|
+
body: string;
|
|
6
|
+
etag: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Frontend files that a `cell build --single` bundle registers before the application starts, by URL
|
|
10
|
+
* path (`/index.html`, `/assets/index-abc.js`). When they are there, they are served from memory
|
|
11
|
+
* instead of `cell.serve-static.root`.
|
|
12
|
+
*/
|
|
13
|
+
export declare namespace EmbeddedAssets {
|
|
14
|
+
const KEY: unique symbol;
|
|
15
|
+
function get(): Map<string, EmbeddedAsset> | undefined;
|
|
16
|
+
/** The counterpart of `serveStatic`: same options, same `next()` when a file is not there. */
|
|
17
|
+
function serve(assets: Map<string, EmbeddedAsset>, opts: ServeStaticOption & {
|
|
18
|
+
maxAge?: number;
|
|
19
|
+
}): (req: any, res: any, next: (err?: unknown) => void, url?: string) => void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=embedded-assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded-assets.d.ts","sourceRoot":"","sources":["../../src/node/embedded-assets.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEhD,+EAA+E;AAC/E,MAAM,WAAW,aAAa;IAC1B,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,yBAAiB,cAAc,CAAC;IACrB,MAAM,GAAG,eAA4C,CAAC;IAK7D,SAAgB,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,SAAS,CAE5D;IAgBD,8FAA8F;IAC9F,SAAgB,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,IAAI,EAAE,iBAAiB,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,SACtF,GAAG,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,QAAO,MAAM,UAuCzE;CACJ"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EmbeddedAssets = void 0;
|
|
7
|
+
const send_1 = __importDefault(require("send"));
|
|
8
|
+
/**
|
|
9
|
+
* Frontend files that a `cell build --single` bundle registers before the application starts, by URL
|
|
10
|
+
* path (`/index.html`, `/assets/index-abc.js`). When they are there, they are served from memory
|
|
11
|
+
* instead of `cell.serve-static.root`.
|
|
12
|
+
*/
|
|
13
|
+
var EmbeddedAssets;
|
|
14
|
+
(function (EmbeddedAssets) {
|
|
15
|
+
EmbeddedAssets.KEY = Symbol.for('@celljs/serve-static/assets');
|
|
16
|
+
/** Decoded bodies, per table of assets: a table that is registered again is decoded again. */
|
|
17
|
+
const decoded = new WeakMap();
|
|
18
|
+
function get() {
|
|
19
|
+
return globalThis[EmbeddedAssets.KEY];
|
|
20
|
+
}
|
|
21
|
+
EmbeddedAssets.get = get;
|
|
22
|
+
function content(assets, path, asset) {
|
|
23
|
+
let bodies = decoded.get(assets);
|
|
24
|
+
if (!bodies) {
|
|
25
|
+
bodies = new Map();
|
|
26
|
+
decoded.set(assets, bodies);
|
|
27
|
+
}
|
|
28
|
+
let body = bodies.get(path);
|
|
29
|
+
if (!body) {
|
|
30
|
+
body = Buffer.from(asset.body, 'base64');
|
|
31
|
+
bodies.set(path, body);
|
|
32
|
+
}
|
|
33
|
+
return body;
|
|
34
|
+
}
|
|
35
|
+
/** The counterpart of `serveStatic`: same options, same `next()` when a file is not there. */
|
|
36
|
+
function serve(assets, opts) {
|
|
37
|
+
return (req, res, next, url = req.url) => {
|
|
38
|
+
var _a;
|
|
39
|
+
var _b, _c;
|
|
40
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
41
|
+
next();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let path;
|
|
45
|
+
try {
|
|
46
|
+
path = decodeURIComponent(new URL(url.replace(opts.baseHref, '/'), 'http://localhost').pathname);
|
|
47
|
+
}
|
|
48
|
+
catch (_d) {
|
|
49
|
+
next();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (path.endsWith('/')) {
|
|
53
|
+
path += 'index.html';
|
|
54
|
+
}
|
|
55
|
+
const asset = assets.get(path);
|
|
56
|
+
if (!asset) {
|
|
57
|
+
next();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const type = send_1.default.mime.lookup(path);
|
|
61
|
+
const charset = send_1.default.mime.charsets.lookup(type);
|
|
62
|
+
res.setHeader('Content-Type', charset ? `${type}; charset=${charset}` : type);
|
|
63
|
+
res.setHeader('ETag', asset.etag);
|
|
64
|
+
if (opts.cacheControl !== false) {
|
|
65
|
+
const maxAge = Math.floor(Math.min(Math.max(0, Number((_c = (_b = opts.maxAge) !== null && _b !== void 0 ? _b : opts.maxage) !== null && _c !== void 0 ? _c : 0)), 31536000000) / 1000);
|
|
66
|
+
res.setHeader('Cache-Control', `public, max-age=${maxAge}${opts.immutable ? ', immutable' : ''}`);
|
|
67
|
+
}
|
|
68
|
+
(_a = opts.setHeaders) === null || _a === void 0 ? void 0 : _a.call(opts, res, path, undefined);
|
|
69
|
+
if (req.headers['if-none-match'] === asset.etag) {
|
|
70
|
+
res.statusCode = 304;
|
|
71
|
+
res.end();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const body = content(assets, path, asset);
|
|
75
|
+
res.statusCode = 200;
|
|
76
|
+
res.setHeader('Content-Length', body.length);
|
|
77
|
+
res.end(req.method === 'HEAD' ? undefined : body);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
EmbeddedAssets.serve = serve;
|
|
81
|
+
})(EmbeddedAssets || (exports.EmbeddedAssets = EmbeddedAssets = {}));
|
|
82
|
+
//# sourceMappingURL=embedded-assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded-assets.js","sourceRoot":"","sources":["../../src/node/embedded-assets.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAUxB;;;;GAIG;AACH,IAAiB,cAAc,CAkE9B;AAlED,WAAiB,cAAc;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AI,CAAC,UAAU,+CAAf,IAAI,EAAc,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;YACxC,IAAI,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;gBAC9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;gBACrB,GAAG,CAAC,GAAG,EAAE,CAAC;gBACV,OAAO;YACX,CAAC;YACD,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7C,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACtD,CAAC,CAAC;IACN,CAAC;IAxCe,eAAA,KAAK,QAwCpB,CAAA;AACL,CAAC,EAlEgB,cAAc,aAAd,cAAc,GAAd,cAAc,QAkE9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded-assets.spec.d.ts","sourceRoot":"","sources":["../../src/node/embedded-assets.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const chai_1 = require("chai");
|
|
5
|
+
const embedded_assets_1 = require("./embedded-assets");
|
|
6
|
+
function request(url, opts = {}, method = 'GET', headers = {}) {
|
|
7
|
+
const assets = new Map([
|
|
8
|
+
['/index.html', { body: Buffer.from('<html></html>').toString('base64'), etag: '"a"' }],
|
|
9
|
+
['/assets/app.js', { body: Buffer.from('run()').toString('base64'), etag: '"b"' }],
|
|
10
|
+
]);
|
|
11
|
+
const sent = { headers: {}, next: false };
|
|
12
|
+
const res = {
|
|
13
|
+
statusCode: 0,
|
|
14
|
+
setHeader: (name, value) => {
|
|
15
|
+
sent.headers[name.toLowerCase()] = value;
|
|
16
|
+
},
|
|
17
|
+
end: (body) => {
|
|
18
|
+
sent.status = res.statusCode;
|
|
19
|
+
sent.body = body;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
embedded_assets_1.EmbeddedAssets.serve(assets, { baseHref: '/', root: '', ...opts })({ url, method, headers }, res, () => {
|
|
23
|
+
sent.next = true;
|
|
24
|
+
});
|
|
25
|
+
return sent;
|
|
26
|
+
}
|
|
27
|
+
(0, bun_test_1.describe)('EmbeddedAssets', () => {
|
|
28
|
+
(0, bun_test_1.it)('serves files from memory with type, length, ETag and cache headers', () => {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
const js = request('/assets/app.js', { maxAge: 31536000000, immutable: true });
|
|
31
|
+
(0, chai_1.expect)(js.status).to.equal(200);
|
|
32
|
+
(0, chai_1.expect)((_a = js.body) === null || _a === void 0 ? void 0 : _a.toString()).to.equal('run()');
|
|
33
|
+
(0, chai_1.expect)(js.headers).to.include({
|
|
34
|
+
'content-type': 'application/javascript; charset=UTF-8',
|
|
35
|
+
'content-length': 5,
|
|
36
|
+
etag: '"b"',
|
|
37
|
+
'cache-control': 'public, max-age=31536000, immutable',
|
|
38
|
+
});
|
|
39
|
+
(0, chai_1.expect)((_b = request('/').body) === null || _b === void 0 ? void 0 : _b.toString()).to.equal('<html></html>');
|
|
40
|
+
(0, chai_1.expect)(request('/index.html').headers['content-type']).to.equal('text/html; charset=UTF-8');
|
|
41
|
+
});
|
|
42
|
+
(0, bun_test_1.it)('answers HEAD without a body and If-None-Match with 304', () => {
|
|
43
|
+
const head = request('/assets/app.js', {}, 'HEAD');
|
|
44
|
+
(0, chai_1.expect)(head.status).to.equal(200);
|
|
45
|
+
(0, chai_1.expect)(head.body).to.equal(undefined);
|
|
46
|
+
(0, chai_1.expect)(request('/assets/app.js', {}, 'GET', { 'if-none-match': '"b"' }).status).to.equal(304);
|
|
47
|
+
});
|
|
48
|
+
(0, bun_test_1.it)('passes on what it does not have, other methods and the base href', () => {
|
|
49
|
+
var _a;
|
|
50
|
+
(0, chai_1.expect)(request('/missing.js').next).to.equal(true);
|
|
51
|
+
(0, chai_1.expect)(request('/assets/app.js', {}, 'POST').next).to.equal(true);
|
|
52
|
+
(0, chai_1.expect)((_a = request('/app/assets/app.js', { baseHref: '/app/' }).body) === null || _a === void 0 ? void 0 : _a.toString()).to.equal('run()');
|
|
53
|
+
(0, chai_1.expect)(request('/%E0%A4%A').next).to.equal(true);
|
|
54
|
+
});
|
|
55
|
+
(0, bun_test_1.it)('is found under a global symbol shared with the build', () => {
|
|
56
|
+
(0, chai_1.expect)(embedded_assets_1.EmbeddedAssets.KEY).to.equal(Symbol.for('@celljs/serve-static/assets'));
|
|
57
|
+
(0, chai_1.expect)(embedded_assets_1.EmbeddedAssets.get()).to.equal(undefined);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=embedded-assets.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded-assets.spec.js","sourceRoot":"","sources":["../../src/node/embedded-assets.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,uDAAmD;AASnD,SAAS,OAAO,CAAC,GAAW,EAAE,IAAI,GAA4B,EAAE,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,GAA2B,EAAE;IAClH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC;QACnB,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QACvF,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC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OAAO,CAAC,gBAAgB,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClE,IAAA,aAAM,EAAC,MAAA,OAAO,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,0CAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAChG,IAAA,aAAM,EAAC,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,sDAAsD,EAAE,GAAG,EAAE;QAC5D,IAAA,aAAM,EAAC,gCAAc,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC,CAAC;QAC/E,IAAA,aAAM,EAAC,gCAAc,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/lib/node/index.d.ts
CHANGED
package/lib/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AACA,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AACA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC"}
|
package/lib/node/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./serve-static-middleware"), exports);
|
|
18
|
+
__exportStar(require("./embedded-assets"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/lib/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,4DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,4DAA0C;AAC1C,oDAAkC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Middleware, Context, RequestMatcher } from '@celljs/web/lib/node';
|
|
2
|
+
import { OutgoingMessage } from 'http';
|
|
3
|
+
import type { ServeStaticOption } from './type';
|
|
4
|
+
type Serve = (req: any, res: any, next: (err?: any) => void, url?: string) => void;
|
|
2
5
|
export declare class ServeStaticMiddleware implements Middleware {
|
|
3
6
|
protected config: {
|
|
4
7
|
spa: boolean;
|
|
@@ -9,7 +12,26 @@ export declare class ServeStaticMiddleware implements Middleware {
|
|
|
9
12
|
};
|
|
10
13
|
protected path: string;
|
|
11
14
|
protected readonly requestMatcher: RequestMatcher;
|
|
15
|
+
/**
|
|
16
|
+
* Whether there is a frontend to serve: embedded in the bundle (`--single`) or on disk. On
|
|
17
|
+
* Cloudflare Workers the platform serves the frontend and the worker has no copy.
|
|
18
|
+
*/
|
|
19
|
+
protected hasFrontend: boolean;
|
|
20
|
+
/** Options of the file server: a copy of `cell.serve-static.options`, which stays untouched. */
|
|
21
|
+
protected options: ServeStaticOption & Record<string, any>;
|
|
22
|
+
protected serve: Serve;
|
|
23
|
+
/**
|
|
24
|
+
* Sets up the file server once. Cloudflare Workers allow I/O (`existsSync`) only while a request is
|
|
25
|
+
* handled; the application, and with it this component, starts on the first request there.
|
|
26
|
+
*/
|
|
27
|
+
protected init(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Adds the configured `headers` to every file, and gives HTML files their own Cache-Control
|
|
30
|
+
* (`htmlMaxAge` in milliseconds, default 0) so that a new build of the page is picked up.
|
|
31
|
+
*/
|
|
32
|
+
protected createSetHeaders(headers: Record<string, string> | undefined, htmlMaxAge: unknown): (res: OutgoingMessage, path: string) => void;
|
|
12
33
|
handle(ctx: Context, next: () => Promise<void>): Promise<void>;
|
|
13
34
|
priority: number;
|
|
14
35
|
}
|
|
36
|
+
export {};
|
|
15
37
|
//# sourceMappingURL=serve-static-middleware.d.ts.map
|