@@ -11,6 +11,7 @@ const ext = (opts: TemplateOptions) => (opts.typescript ? ".ts" : ".js");
1111export function packageJson ( opts : TemplateOptions ) : string {
1212 const deps : Record < string , string > = {
1313 marko : "^6.0.0" ,
14+ "@marko/runtime-tags" : "^6.0.0" ,
1415 } ;
1516 const devDeps : Record < string , string > = {
1617 "@markopack/rspack" : "^0.1.0" ,
@@ -128,14 +129,14 @@ import path from "node:path";
128129
129130const root = import.meta.dirname;
130131const port = Number(process.env.PORT || 3000);
131- const publicDir = path.join(root, "dist/client ");
132+ const publicDir = path.join(root, "dist/server/public ");
132133
133134if (!fs.existsSync(publicDir)) {
134135 console.error("No build found. Run \`npm run build\` first.");
135136 process.exit(1);
136137}
137138
138- const mimeTypes: Record<string, string> = {
139+ const mimeTypes = {
139140 ".html": "text/html",
140141 ".js": "application/javascript",
141142 ".css": "text/css",
@@ -146,11 +147,19 @@ const mimeTypes: Record<string, string> = {
146147 ".ico": "image/x-icon",
147148};
148149
150+ function resolveFile(urlPath) {
151+ if (urlPath === "/") return path.join(publicDir, "index.html");
152+ const base = path.join(publicDir, urlPath);
153+ if (fs.existsSync(base) && !fs.statSync(base).isDirectory()) return base;
154+ const withExt = base + ".html";
155+ if (fs.existsSync(withExt)) return withExt;
156+ const asIndex = path.join(base, "index.html");
157+ if (fs.existsSync(asIndex)) return asIndex;
158+ return null;
159+ }
160+
149161const server = http.createServer((req, res) => {
150- let filePath = path.join(publicDir, req.url === "/" ? "index.html" : req.url!);
151- if (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) {
152- filePath = path.join(publicDir, "index.html");
153- }
162+ const filePath = resolveFile(req.url) || path.join(publicDir, "404.html");
154163 const ext = path.extname(filePath);
155164 res.setHeader("Content-Type", mimeTypes[ext] || "application/octet-stream");
156165 fs.createReadStream(filePath).pipe(res);
0 commit comments