aethex-forge/vite.config.ts
sirpiglr 855c518623 Configure Vite to work with Replit and secure file system access
Update Vite configuration to use port 5000 and host 0.0.0.0 for Replit compatibility, adjust fs.allow and fs.deny settings for improved security, and add a replit.md documentation file.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9203795e-937a-4306-b81d-b4d5c78c240e
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 03255903-d5eb-4d8a-aaac-72c01c2fedf6
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7c94b7a0-29c7-4f2e-94ef-44b2153872b7/9203795e-937a-4306-b81d-b4d5c78c240e/dxDbFOs
Replit-Helium-Checkpoint-Created: true
2025-12-02 18:11:51 +00:00

61 lines
1.7 KiB
TypeScript

import { defineConfig, Plugin } from "vite";
import react from "@vitejs/plugin-react-swc";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
server: {
host: "0.0.0.0",
port: 5000,
strictPort: true,
hmr: {
clientPort: 5000,
},
fs: {
allow: [path.resolve(__dirname, "./client"), path.resolve(__dirname, "./shared"), path.resolve(__dirname, "./node_modules"), path.resolve(__dirname)],
deny: [".env", ".env.*", "*.{crt,pem}", "**/.git/**", "server/**", "api/**", "discord-bot/**"],
},
},
build: {
outDir: "dist/spa",
},
plugins: [react(), expressPlugin()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./client"),
"@shared": path.resolve(__dirname, "./shared"),
},
},
}));
function expressPlugin(): Plugin {
return {
name: "express-plugin",
apply: "serve",
async configureServer(server) {
try {
console.log("[Vite] Loading Express server...");
const { createServer } = await import("./server");
const app = createServer();
console.log("[Vite] Express server created, mounting...");
// Mount Express as middleware - this handles /api/* routes
// Using unshift to add it to the beginning of the middleware chain
server.middlewares.stack.unshift({
route: "",
handle: app,
});
console.log("[Vite] Express server mounted successfully");
} catch (e) {
console.error(
"[Vite] Failed to load Express server:",
e instanceof Error ? e.message : String(e),
);
if (e instanceof Error && e.stack) {
console.error(e.stack);
}
}
},
};
}