designpaca/apps/site/astro.config.mjs

50 lines
1.6 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
import url from "node:url";
import { defineConfig } from "astro/config";
const publicDir = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), "public");
export default defineConfig({
site: "https://designpaca.chanpaca.net",
// 정적 출력 — Cloudflare Pages 로 그대로 올린다
output: "static",
build: { format: "directory" },
devToolbar: { enabled: false },
vite: {
server: {
watch: {
ignored: ["**/.astro/**"],
},
},
plugins: [
{
name: "public-dir-index",
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url) {
const [pathname, search = ""] = req.url.split("?");
if (pathname && pathname.startsWith("/work/")) {
if (pathname.endsWith("/")) {
const candidate = path.join(publicDir, pathname, "index.html");
if (fs.existsSync(candidate)) {
req.url = `${pathname}index.html${search ? `?${search}` : ""}`;
}
} else if (!path.extname(pathname)) {
const candidate = path.join(publicDir, pathname, "index.html");
if (fs.existsSync(candidate)) {
res.statusCode = 302;
res.setHeader("Location", `${pathname}/${search ? `?${search}` : ""}`);
res.end();
return;
}
}
}
}
next();
});
},
},
],
},
});