Init: RoggioApp Architecture, Prisma Schema, API MVP
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
|
||||
//#region src/conninfo.ts
|
||||
/**
|
||||
* ConnInfo Helper for Node.js
|
||||
* @param c Context
|
||||
* @returns ConnInfo
|
||||
*/
|
||||
const getConnInfo = (c) => {
|
||||
const bindings = c.env.server ? c.env.server : c.env;
|
||||
const address = bindings.incoming.socket.remoteAddress;
|
||||
const port = bindings.incoming.socket.remotePort;
|
||||
const family = bindings.incoming.socket.remoteFamily;
|
||||
return { remote: {
|
||||
address,
|
||||
port,
|
||||
addressType: family === "IPv4" ? "IPv4" : family === "IPv6" ? "IPv6" : void 0
|
||||
} };
|
||||
};
|
||||
|
||||
//#endregion
|
||||
exports.getConnInfo = getConnInfo;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { GetConnInfo } from "hono/conninfo";
|
||||
|
||||
//#region src/conninfo.d.ts
|
||||
/**
|
||||
* ConnInfo Helper for Node.js
|
||||
* @param c Context
|
||||
* @returns ConnInfo
|
||||
*/
|
||||
declare const getConnInfo: GetConnInfo;
|
||||
//#endregion
|
||||
export { getConnInfo };
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { GetConnInfo } from "hono/conninfo";
|
||||
|
||||
//#region src/conninfo.d.ts
|
||||
/**
|
||||
* ConnInfo Helper for Node.js
|
||||
* @param c Context
|
||||
* @returns ConnInfo
|
||||
*/
|
||||
declare const getConnInfo: GetConnInfo;
|
||||
//#endregion
|
||||
export { getConnInfo };
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//#region src/conninfo.ts
|
||||
/**
|
||||
* ConnInfo Helper for Node.js
|
||||
* @param c Context
|
||||
* @returns ConnInfo
|
||||
*/
|
||||
const getConnInfo = (c) => {
|
||||
const bindings = c.env.server ? c.env.server : c.env;
|
||||
const address = bindings.incoming.socket.remoteAddress;
|
||||
const port = bindings.incoming.socket.remotePort;
|
||||
const family = bindings.incoming.socket.remoteFamily;
|
||||
return { remote: {
|
||||
address,
|
||||
port,
|
||||
addressType: family === "IPv4" ? "IPv4" : family === "IPv6" ? "IPv6" : void 0
|
||||
} };
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { getConnInfo };
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
//#region src/utils/response/constants.ts
|
||||
const X_ALREADY_SENT = "x-hono-already-sent";
|
||||
|
||||
//#endregion
|
||||
export { X_ALREADY_SENT as t };
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
//#region src/utils/response/constants.ts
|
||||
const X_ALREADY_SENT = "x-hono-already-sent";
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'X_ALREADY_SENT', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return X_ALREADY_SENT;
|
||||
}
|
||||
});
|
||||
+1006
File diff suppressed because it is too large
Load Diff
+73
@@ -0,0 +1,73 @@
|
||||
import { AddressInfo } from "node:net";
|
||||
import { WebSocket, WebSocketServer } from "ws";
|
||||
import { IncomingMessage, Server, ServerOptions, ServerResponse, createServer } from "node:http";
|
||||
import { Http2SecureServer, Http2Server, Http2ServerRequest, Http2ServerResponse, SecureServerOptions, ServerOptions as ServerOptions$1, createSecureServer, createServer as createServer$1 } from "node:http2";
|
||||
import { ServerOptions as ServerOptions$2, createServer as createServer$2 } from "node:https";
|
||||
import { UpgradeWebSocket } from "hono/ws";
|
||||
|
||||
//#region src/types.d.ts
|
||||
type HttpBindings = {
|
||||
incoming: IncomingMessage;
|
||||
outgoing: ServerResponse;
|
||||
};
|
||||
type Http2Bindings = {
|
||||
incoming: Http2ServerRequest;
|
||||
outgoing: Http2ServerResponse;
|
||||
};
|
||||
type FetchCallback = (request: Request, env: HttpBindings | Http2Bindings) => Promise<unknown> | unknown;
|
||||
type ServerType = Server | Http2Server | Http2SecureServer;
|
||||
type createHttpOptions = {
|
||||
serverOptions?: ServerOptions;
|
||||
createServer?: typeof createServer;
|
||||
};
|
||||
type createHttpsOptions = {
|
||||
serverOptions?: ServerOptions$2;
|
||||
createServer?: typeof createServer$2;
|
||||
};
|
||||
type createHttp2Options = {
|
||||
serverOptions?: ServerOptions$1;
|
||||
createServer?: typeof createServer$1;
|
||||
};
|
||||
type createSecureHttp2Options = {
|
||||
serverOptions?: SecureServerOptions;
|
||||
createServer?: typeof createSecureServer;
|
||||
};
|
||||
type ServerOptions$3 = createHttpOptions | createHttpsOptions | createHttp2Options | createSecureHttp2Options;
|
||||
type Options = {
|
||||
fetch: FetchCallback;
|
||||
overrideGlobalObjects?: boolean;
|
||||
autoCleanupIncoming?: boolean;
|
||||
port?: number;
|
||||
hostname?: string;
|
||||
websocket?: {
|
||||
server: WebSocketServer;
|
||||
};
|
||||
} & ServerOptions$3;
|
||||
type CustomErrorHandler = (err: unknown) => void | Response | Promise<void | Response>;
|
||||
//#endregion
|
||||
//#region src/server.d.ts
|
||||
declare const createAdaptorServer: (options: Options) => ServerType;
|
||||
declare const serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType;
|
||||
//#endregion
|
||||
//#region src/websocket.d.ts
|
||||
type UpgradeWebSocketOptions = {
|
||||
onError: (err: unknown) => void;
|
||||
};
|
||||
declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, UpgradeWebSocketOptions>;
|
||||
//#endregion
|
||||
//#region src/listener.d.ts
|
||||
declare const getRequestListener: (fetchCallback: FetchCallback, options?: {
|
||||
hostname?: string;
|
||||
errorHandler?: CustomErrorHandler;
|
||||
overrideGlobalObjects?: boolean;
|
||||
autoCleanupIncoming?: boolean;
|
||||
}) => (incoming: IncomingMessage | Http2ServerRequest, outgoing: ServerResponse | Http2ServerResponse) => Promise<void>;
|
||||
//#endregion
|
||||
//#region src/error.d.ts
|
||||
declare class RequestError extends Error {
|
||||
constructor(message: string, options?: {
|
||||
cause?: unknown;
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
export { type Http2Bindings, type HttpBindings, RequestError, type ServerType, createAdaptorServer, getRequestListener, serve, upgradeWebSocket };
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
import { IncomingMessage, Server, ServerOptions, ServerResponse, createServer } from "node:http";
|
||||
import { Http2SecureServer, Http2Server, Http2ServerRequest, Http2ServerResponse, SecureServerOptions, ServerOptions as ServerOptions$1, createSecureServer, createServer as createServer$1 } from "node:http2";
|
||||
import { UpgradeWebSocket } from "hono/ws";
|
||||
import { AddressInfo } from "node:net";
|
||||
import { WebSocket, WebSocketServer } from "ws";
|
||||
import { ServerOptions as ServerOptions$2, createServer as createServer$2 } from "node:https";
|
||||
|
||||
//#region src/types.d.ts
|
||||
type HttpBindings = {
|
||||
incoming: IncomingMessage;
|
||||
outgoing: ServerResponse;
|
||||
};
|
||||
type Http2Bindings = {
|
||||
incoming: Http2ServerRequest;
|
||||
outgoing: Http2ServerResponse;
|
||||
};
|
||||
type FetchCallback = (request: Request, env: HttpBindings | Http2Bindings) => Promise<unknown> | unknown;
|
||||
type ServerType = Server | Http2Server | Http2SecureServer;
|
||||
type createHttpOptions = {
|
||||
serverOptions?: ServerOptions;
|
||||
createServer?: typeof createServer;
|
||||
};
|
||||
type createHttpsOptions = {
|
||||
serverOptions?: ServerOptions$2;
|
||||
createServer?: typeof createServer$2;
|
||||
};
|
||||
type createHttp2Options = {
|
||||
serverOptions?: ServerOptions$1;
|
||||
createServer?: typeof createServer$1;
|
||||
};
|
||||
type createSecureHttp2Options = {
|
||||
serverOptions?: SecureServerOptions;
|
||||
createServer?: typeof createSecureServer;
|
||||
};
|
||||
type ServerOptions$3 = createHttpOptions | createHttpsOptions | createHttp2Options | createSecureHttp2Options;
|
||||
type Options = {
|
||||
fetch: FetchCallback;
|
||||
overrideGlobalObjects?: boolean;
|
||||
autoCleanupIncoming?: boolean;
|
||||
port?: number;
|
||||
hostname?: string;
|
||||
websocket?: {
|
||||
server: WebSocketServer;
|
||||
};
|
||||
} & ServerOptions$3;
|
||||
type CustomErrorHandler = (err: unknown) => void | Response | Promise<void | Response>;
|
||||
//#endregion
|
||||
//#region src/server.d.ts
|
||||
declare const createAdaptorServer: (options: Options) => ServerType;
|
||||
declare const serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType;
|
||||
//#endregion
|
||||
//#region src/websocket.d.ts
|
||||
type UpgradeWebSocketOptions = {
|
||||
onError: (err: unknown) => void;
|
||||
};
|
||||
declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, UpgradeWebSocketOptions>;
|
||||
//#endregion
|
||||
//#region src/listener.d.ts
|
||||
declare const getRequestListener: (fetchCallback: FetchCallback, options?: {
|
||||
hostname?: string;
|
||||
errorHandler?: CustomErrorHandler;
|
||||
overrideGlobalObjects?: boolean;
|
||||
autoCleanupIncoming?: boolean;
|
||||
}) => (incoming: IncomingMessage | Http2ServerRequest, outgoing: ServerResponse | Http2ServerResponse) => Promise<void>;
|
||||
//#endregion
|
||||
//#region src/error.d.ts
|
||||
declare class RequestError extends Error {
|
||||
constructor(message: string, options?: {
|
||||
cause?: unknown;
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
export { type Http2Bindings, type HttpBindings, RequestError, type ServerType, createAdaptorServer, getRequestListener, serve, upgradeWebSocket };
|
||||
+1001
File diff suppressed because it is too large
Load Diff
+135
@@ -0,0 +1,135 @@
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
let node_stream = require("node:stream");
|
||||
let hono_utils_mime = require("hono/utils/mime");
|
||||
let node_fs = require("node:fs");
|
||||
let node_path = require("node:path");
|
||||
let node_process = require("node:process");
|
||||
|
||||
//#region src/serve-static.ts
|
||||
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
||||
const ENCODINGS = {
|
||||
br: ".br",
|
||||
zstd: ".zst",
|
||||
gzip: ".gz"
|
||||
};
|
||||
const ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
||||
const pr54206Applied = () => {
|
||||
const [major, minor] = node_process.versions.node.split(".").map((component) => parseInt(component));
|
||||
return major >= 23 || major === 22 && minor >= 7 || major === 20 && minor >= 18;
|
||||
};
|
||||
const useReadableToWeb = pr54206Applied();
|
||||
const createStreamBody = (stream) => {
|
||||
if (useReadableToWeb) return node_stream.Readable.toWeb(stream);
|
||||
return new ReadableStream({
|
||||
start(controller) {
|
||||
stream.on("data", (chunk) => {
|
||||
controller.enqueue(chunk);
|
||||
});
|
||||
stream.on("error", (err) => {
|
||||
controller.error(err);
|
||||
});
|
||||
stream.on("end", () => {
|
||||
controller.close();
|
||||
});
|
||||
},
|
||||
cancel() {
|
||||
stream.destroy();
|
||||
}
|
||||
});
|
||||
};
|
||||
const getStats = (path) => {
|
||||
let stats;
|
||||
try {
|
||||
stats = (0, node_fs.statSync)(path);
|
||||
} catch {}
|
||||
return stats;
|
||||
};
|
||||
const tryDecode = (str, decoder) => {
|
||||
try {
|
||||
return decoder(str);
|
||||
} catch {
|
||||
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
||||
try {
|
||||
return decoder(match);
|
||||
} catch {
|
||||
return match;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
const tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
||||
const serveStatic = (options = { root: "" }) => {
|
||||
const root = options.root || "";
|
||||
const optionPath = options.path;
|
||||
if (root !== "" && !(0, node_fs.existsSync)(root)) console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
|
||||
return async (c, next) => {
|
||||
if (c.finalized) return next();
|
||||
let filename;
|
||||
if (optionPath) filename = optionPath;
|
||||
else try {
|
||||
filename = tryDecodeURI(c.req.path);
|
||||
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}/.test(filename)) throw new Error();
|
||||
} catch {
|
||||
await options.onNotFound?.(c.req.path, c);
|
||||
return next();
|
||||
}
|
||||
let path = (0, node_path.join)(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename);
|
||||
let stats = getStats(path);
|
||||
if (stats && stats.isDirectory()) {
|
||||
const indexFile = options.index ?? "index.html";
|
||||
path = (0, node_path.join)(path, indexFile);
|
||||
stats = getStats(path);
|
||||
}
|
||||
if (!stats) {
|
||||
await options.onNotFound?.(path, c);
|
||||
return next();
|
||||
}
|
||||
const mimeType = (0, hono_utils_mime.getMimeType)(path);
|
||||
c.header("Content-Type", mimeType || "application/octet-stream");
|
||||
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
||||
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
|
||||
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
||||
if (!acceptEncodingSet.has(encoding)) continue;
|
||||
const precompressedStats = getStats(path + ENCODINGS[encoding]);
|
||||
if (precompressedStats) {
|
||||
c.header("Content-Encoding", encoding);
|
||||
c.header("Vary", "Accept-Encoding", { append: true });
|
||||
stats = precompressedStats;
|
||||
path = path + ENCODINGS[encoding];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
let result;
|
||||
const size = stats.size;
|
||||
const range = c.req.header("range") || "";
|
||||
if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
|
||||
c.header("Content-Length", size.toString());
|
||||
c.status(200);
|
||||
result = c.body(null);
|
||||
} else if (!range) {
|
||||
c.header("Content-Length", size.toString());
|
||||
result = c.body(createStreamBody((0, node_fs.createReadStream)(path)), 200);
|
||||
} else {
|
||||
c.header("Accept-Ranges", "bytes");
|
||||
c.header("Date", stats.birthtime.toUTCString());
|
||||
const parts = range.replace(/bytes=/, "").split("-", 2);
|
||||
const start = parseInt(parts[0], 10) || 0;
|
||||
let end = parseInt(parts[1], 10) || size - 1;
|
||||
if (size < end - start + 1) end = size - 1;
|
||||
const chunksize = end - start + 1;
|
||||
const stream = (0, node_fs.createReadStream)(path, {
|
||||
start,
|
||||
end
|
||||
});
|
||||
c.header("Content-Length", chunksize.toString());
|
||||
c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
||||
result = c.body(createStreamBody(stream), 206);
|
||||
}
|
||||
await options.onFound?.(path, c);
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
//#endregion
|
||||
exports.serveStatic = serveStatic;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Context, Env, MiddlewareHandler } from "hono";
|
||||
|
||||
//#region src/serve-static.d.ts
|
||||
type ServeStaticOptions<E extends Env = Env> = {
|
||||
/**
|
||||
* Root path, relative to current working directory from which the app was started. Absolute paths are not supported.
|
||||
*/
|
||||
root?: string;
|
||||
path?: string;
|
||||
index?: string;
|
||||
precompressed?: boolean;
|
||||
rewriteRequestPath?: (path: string, c: Context<E>) => string;
|
||||
onFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
||||
onNotFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
||||
};
|
||||
declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
|
||||
//#endregion
|
||||
export { ServeStaticOptions, serveStatic };
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Context, Env, MiddlewareHandler } from "hono";
|
||||
|
||||
//#region src/serve-static.d.ts
|
||||
type ServeStaticOptions<E extends Env = Env> = {
|
||||
/**
|
||||
* Root path, relative to current working directory from which the app was started. Absolute paths are not supported.
|
||||
*/
|
||||
root?: string;
|
||||
path?: string;
|
||||
index?: string;
|
||||
precompressed?: boolean;
|
||||
rewriteRequestPath?: (path: string, c: Context<E>) => string;
|
||||
onFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
||||
onNotFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
||||
};
|
||||
declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
|
||||
//#endregion
|
||||
export { ServeStaticOptions, serveStatic };
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
import { Readable } from "node:stream";
|
||||
import { getMimeType } from "hono/utils/mime";
|
||||
import { createReadStream, existsSync, statSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { versions } from "node:process";
|
||||
|
||||
//#region src/serve-static.ts
|
||||
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
||||
const ENCODINGS = {
|
||||
br: ".br",
|
||||
zstd: ".zst",
|
||||
gzip: ".gz"
|
||||
};
|
||||
const ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
||||
const pr54206Applied = () => {
|
||||
const [major, minor] = versions.node.split(".").map((component) => parseInt(component));
|
||||
return major >= 23 || major === 22 && minor >= 7 || major === 20 && minor >= 18;
|
||||
};
|
||||
const useReadableToWeb = pr54206Applied();
|
||||
const createStreamBody = (stream) => {
|
||||
if (useReadableToWeb) return Readable.toWeb(stream);
|
||||
return new ReadableStream({
|
||||
start(controller) {
|
||||
stream.on("data", (chunk) => {
|
||||
controller.enqueue(chunk);
|
||||
});
|
||||
stream.on("error", (err) => {
|
||||
controller.error(err);
|
||||
});
|
||||
stream.on("end", () => {
|
||||
controller.close();
|
||||
});
|
||||
},
|
||||
cancel() {
|
||||
stream.destroy();
|
||||
}
|
||||
});
|
||||
};
|
||||
const getStats = (path) => {
|
||||
let stats;
|
||||
try {
|
||||
stats = statSync(path);
|
||||
} catch {}
|
||||
return stats;
|
||||
};
|
||||
const tryDecode = (str, decoder) => {
|
||||
try {
|
||||
return decoder(str);
|
||||
} catch {
|
||||
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
||||
try {
|
||||
return decoder(match);
|
||||
} catch {
|
||||
return match;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
const tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
||||
const serveStatic = (options = { root: "" }) => {
|
||||
const root = options.root || "";
|
||||
const optionPath = options.path;
|
||||
if (root !== "" && !existsSync(root)) console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
|
||||
return async (c, next) => {
|
||||
if (c.finalized) return next();
|
||||
let filename;
|
||||
if (optionPath) filename = optionPath;
|
||||
else try {
|
||||
filename = tryDecodeURI(c.req.path);
|
||||
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}/.test(filename)) throw new Error();
|
||||
} catch {
|
||||
await options.onNotFound?.(c.req.path, c);
|
||||
return next();
|
||||
}
|
||||
let path = join(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename);
|
||||
let stats = getStats(path);
|
||||
if (stats && stats.isDirectory()) {
|
||||
const indexFile = options.index ?? "index.html";
|
||||
path = join(path, indexFile);
|
||||
stats = getStats(path);
|
||||
}
|
||||
if (!stats) {
|
||||
await options.onNotFound?.(path, c);
|
||||
return next();
|
||||
}
|
||||
const mimeType = getMimeType(path);
|
||||
c.header("Content-Type", mimeType || "application/octet-stream");
|
||||
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
||||
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
|
||||
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
||||
if (!acceptEncodingSet.has(encoding)) continue;
|
||||
const precompressedStats = getStats(path + ENCODINGS[encoding]);
|
||||
if (precompressedStats) {
|
||||
c.header("Content-Encoding", encoding);
|
||||
c.header("Vary", "Accept-Encoding", { append: true });
|
||||
stats = precompressedStats;
|
||||
path = path + ENCODINGS[encoding];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
let result;
|
||||
const size = stats.size;
|
||||
const range = c.req.header("range") || "";
|
||||
if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
|
||||
c.header("Content-Length", size.toString());
|
||||
c.status(200);
|
||||
result = c.body(null);
|
||||
} else if (!range) {
|
||||
c.header("Content-Length", size.toString());
|
||||
result = c.body(createStreamBody(createReadStream(path)), 200);
|
||||
} else {
|
||||
c.header("Accept-Ranges", "bytes");
|
||||
c.header("Date", stats.birthtime.toUTCString());
|
||||
const parts = range.replace(/bytes=/, "").split("-", 2);
|
||||
const start = parseInt(parts[0], 10) || 0;
|
||||
let end = parseInt(parts[1], 10) || size - 1;
|
||||
if (size < end - start + 1) end = size - 1;
|
||||
const chunksize = end - start + 1;
|
||||
const stream = createReadStream(path, {
|
||||
start,
|
||||
end
|
||||
});
|
||||
c.header("Content-Length", chunksize.toString());
|
||||
c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
||||
result = c.body(createStreamBody(stream), 206);
|
||||
}
|
||||
await options.onFound?.(path, c);
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { serveStatic };
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
const require_constants = require('../constants-BXAKTxRC.cjs');
|
||||
|
||||
//#region src/utils/response.ts
|
||||
const RESPONSE_ALREADY_SENT = new Response(null, { headers: { [require_constants.X_ALREADY_SENT]: "true" } });
|
||||
|
||||
//#endregion
|
||||
exports.RESPONSE_ALREADY_SENT = RESPONSE_ALREADY_SENT;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
//#region src/utils/response.d.ts
|
||||
declare const RESPONSE_ALREADY_SENT: Response;
|
||||
//#endregion
|
||||
export { RESPONSE_ALREADY_SENT };
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
//#region src/utils/response.d.ts
|
||||
declare const RESPONSE_ALREADY_SENT: Response;
|
||||
//#endregion
|
||||
export { RESPONSE_ALREADY_SENT };
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { t as X_ALREADY_SENT } from "../constants-BLSFu_RU.mjs";
|
||||
|
||||
//#region src/utils/response.ts
|
||||
const RESPONSE_ALREADY_SENT = new Response(null, { headers: { [X_ALREADY_SENT]: "true" } });
|
||||
|
||||
//#endregion
|
||||
export { RESPONSE_ALREADY_SENT };
|
||||
Reference in New Issue
Block a user