formacao
This commit is contained in:
+20
-10
@@ -4,22 +4,30 @@ import { createPool } from "../../utils/concurrent.js";
|
||||
import { getExtension } from "../../utils/mime.js";
|
||||
import { SSG_CONTEXT, X_HONO_DISABLE_SSG_HEADER_KEY } from "./middleware.js";
|
||||
import { defaultPlugin } from "./plugins.js";
|
||||
import { dirname, filterStaticGenerateRoutes, isDynamicRoute, joinPaths } from "./utils.js";
|
||||
import {
|
||||
dirname,
|
||||
ensureWithinOutDir,
|
||||
filterStaticGenerateRoutes,
|
||||
isDynamicRoute,
|
||||
joinPaths
|
||||
} from "./utils.js";
|
||||
var DEFAULT_CONCURRENCY = 2;
|
||||
var DEFAULT_CONTENT_TYPE = "text/plain";
|
||||
var DEFAULT_OUTPUT_DIR = "./static";
|
||||
var generateFilePath = (routePath, outDir, mimeType, extensionMap) => {
|
||||
const extension = determineExtension(mimeType, extensionMap);
|
||||
let filePath;
|
||||
if (routePath.endsWith(`.${extension}`)) {
|
||||
return joinPaths(outDir, routePath);
|
||||
filePath = joinPaths(outDir, routePath);
|
||||
} else if (routePath === "/") {
|
||||
filePath = joinPaths(outDir, `index.${extension}`);
|
||||
} else if (routePath.endsWith("/")) {
|
||||
filePath = joinPaths(outDir, routePath, `index.${extension}`);
|
||||
} else {
|
||||
filePath = joinPaths(outDir, `${routePath}.${extension}`);
|
||||
}
|
||||
if (routePath === "/") {
|
||||
return joinPaths(outDir, `index.${extension}`);
|
||||
}
|
||||
if (routePath.endsWith("/")) {
|
||||
return joinPaths(outDir, routePath, `index.${extension}`);
|
||||
}
|
||||
return joinPaths(outDir, `${routePath}.${extension}`);
|
||||
ensureWithinOutDir(outDir, filePath);
|
||||
return filePath;
|
||||
};
|
||||
var parseResponseContent = async (response) => {
|
||||
const contentType = response.headers.get("Content-Type");
|
||||
@@ -39,6 +47,8 @@ var defaultExtensionMap = {
|
||||
"text/html": "html",
|
||||
"text/xml": "xml",
|
||||
"application/xml": "xml",
|
||||
"application/atom+xml": "xml",
|
||||
"application/rss+xml": "xml",
|
||||
"application/yaml": "yaml"
|
||||
};
|
||||
var determineExtension = (mimeType, userExtensionMap) => {
|
||||
@@ -110,7 +120,7 @@ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, c
|
||||
}
|
||||
forGetInfoURLRequest = maybeRequest;
|
||||
}
|
||||
await pool.run(() => app.fetch(forGetInfoURLRequest));
|
||||
await pool.run(() => app.fetch(forGetInfoURLRequest, { [SSG_CONTEXT]: true }));
|
||||
if (!forGetInfoURLRequest.ssgParams) {
|
||||
if (isDynamicRoute(route.path)) {
|
||||
resolveGetInfo(void 0);
|
||||
|
||||
+8
@@ -51,8 +51,16 @@ var filterStaticGenerateRoutes = (hono) => {
|
||||
var isDynamicRoute = (path) => {
|
||||
return path.split("/").some((segment) => segment.startsWith(":") || segment.includes("*"));
|
||||
};
|
||||
var ensureWithinOutDir = (outDir, filePath) => {
|
||||
const normalizedOutDir = joinPaths("/", outDir);
|
||||
const normalizedFilePath = joinPaths("/", filePath);
|
||||
if (normalizedFilePath !== normalizedOutDir && !normalizedFilePath.startsWith(`${normalizedOutDir}/`)) {
|
||||
throw new Error(`Path traversal detected: "${filePath}" is outside the output directory`);
|
||||
}
|
||||
};
|
||||
export {
|
||||
dirname,
|
||||
ensureWithinOutDir,
|
||||
filterStaticGenerateRoutes,
|
||||
isDynamicRoute,
|
||||
joinPaths
|
||||
|
||||
Reference in New Issue
Block a user