(app: Express)
| 68 | } |
| 69 | |
| 70 | export function serveStatic(app: Express) { |
| 71 | const distPath = path.resolve(import.meta.dirname, "public"); |
| 72 | |
| 73 | if (!fs.existsSync(distPath)) { |
| 74 | throw new Error( |
| 75 | `Could not find the build directory: ${distPath}, make sure to build the client first`, |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | app.use(express.static(distPath)); |
| 80 | |
| 81 | // fall through to index.html if the file doesn't exist |
| 82 | app.use("*", (_req, res) => { |
| 83 | res.sendFile(path.resolve(distPath, "index.html")); |
| 84 | }); |
| 85 | } |