Agent skills
Prettier eslint shopify
This commit is contained in:
+22
-7
@@ -10,7 +10,7 @@
|
||||
import { createServer } from "node:http";
|
||||
import { createReadStream, existsSync, statSync } from "node:fs";
|
||||
import { createGzip } from "node:zlib";
|
||||
import { extname, join, resolve, sep } from "node:path";
|
||||
import { extname, resolve, sep } from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
import handler from "./dist/server/server.js";
|
||||
|
||||
@@ -46,13 +46,24 @@ const MIME = {
|
||||
};
|
||||
|
||||
const COMPRESSIBLE = new Set([
|
||||
".html", ".js", ".mjs", ".css", ".json", ".txt", ".xml", ".map", ".svg",
|
||||
".html",
|
||||
".js",
|
||||
".mjs",
|
||||
".css",
|
||||
".json",
|
||||
".txt",
|
||||
".xml",
|
||||
".map",
|
||||
".svg",
|
||||
".webmanifest",
|
||||
]);
|
||||
|
||||
function isHashedAsset(pathname) {
|
||||
// Vite emits content-hashed filenames under /assets/
|
||||
return pathname.startsWith("/assets/") && /\-[A-Za-z0-9_-]{8}\.[^.]+$/.test(pathname);
|
||||
return (
|
||||
pathname.startsWith("/assets/") &&
|
||||
/-[A-Za-z0-9_-]{8}\.[^.]+$/.test(pathname)
|
||||
);
|
||||
}
|
||||
|
||||
function sendError(res, status, message) {
|
||||
@@ -68,7 +79,8 @@ function tryStatic(req, res, pathname) {
|
||||
|
||||
const rel = pathname.slice(1);
|
||||
const filePath = resolve(CLIENT_ROOT, rel);
|
||||
if (filePath !== CLIENT_ROOT && !filePath.startsWith(CLIENT_ROOT + sep)) return false;
|
||||
if (filePath !== CLIENT_ROOT && !filePath.startsWith(CLIENT_ROOT + sep))
|
||||
return false;
|
||||
if (!existsSync(filePath) || !statSync(filePath).isFile()) return false;
|
||||
|
||||
const ext = extname(filePath).toLowerCase();
|
||||
@@ -112,7 +124,8 @@ async function toWebRequest(req, url) {
|
||||
const headers = new Headers();
|
||||
for (const [key, value] of Object.entries(req.headers)) {
|
||||
if (value === undefined) continue;
|
||||
for (const v of Array.isArray(value) ? value : [value]) headers.append(key, v);
|
||||
for (const v of Array.isArray(value) ? value : [value])
|
||||
headers.append(key, v);
|
||||
}
|
||||
const hasBody = req.method !== "GET" && req.method !== "HEAD";
|
||||
return new Request(url, {
|
||||
@@ -144,9 +157,11 @@ async function sendFromHandler(req, res) {
|
||||
}
|
||||
|
||||
const server = createServer(async (req, res) => {
|
||||
let pathname = "/";
|
||||
let pathname;
|
||||
try {
|
||||
pathname = decodeURIComponent(new URL(req.url ?? "/", "http://localhost").pathname);
|
||||
pathname = decodeURIComponent(
|
||||
new URL(req.url ?? "/", "http://localhost").pathname,
|
||||
);
|
||||
} catch {
|
||||
return sendError(res, 400, "Bad request");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user