mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-15 03:01:39 +00:00
- Set VitePress base to '/docs/' for serving documentation at /docs/ route - Update favicon path in head config to '/docs/favicon.ico' - Add build:site script to build website and docs, then merge outputs
34 lines
919 B
TypeScript
34 lines
919 B
TypeScript
import express from "express";
|
|
import { createServer } from "http";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
async function startServer() {
|
|
const app = express();
|
|
const server = createServer(app);
|
|
|
|
// Serve static files from dist/public in production
|
|
const staticPath =
|
|
process.env.NODE_ENV === "production"
|
|
? path.resolve(__dirname, "public")
|
|
: path.resolve(__dirname, "..", "dist", "public");
|
|
|
|
app.use(express.static(staticPath));
|
|
|
|
// Handle client-side routing - serve index.html for all routes
|
|
app.get("*", (_req, res) => {
|
|
res.sendFile(path.join(staticPath, "index.html"));
|
|
});
|
|
|
|
const port = process.env.PORT || 3000;
|
|
|
|
server.listen(port, () => {
|
|
console.log(`Server running on http://localhost:${port}/`);
|
|
});
|
|
}
|
|
|
|
startServer().catch(console.error);
|