CoolFace
Apppublic

Ditzzy/api

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
static.ts20 linesDownload Raw Back to server
1import express, { type Express } from "express";2import fs from "fs";3import path from "path";4 5export function serveStatic(app: Express) {6  const distPath = path.resolve(__dirname, "public");7  if (!fs.existsSync(distPath)) {8    throw new Error(9      `Could not find the build directory: ${distPath}, make sure to build the client first`,10    );11  }12 13  app.use(express.static(distPath));14 15  // fall through to index.html if the file doesn't exist16  app.use((req, res) => {17    res.sendFile(path.resolve(distPath, "index.html"));18  });19}20