Spaces:
Sleeping
Sleeping
Download backend/src/app.ts from cuteepeiarchu/PathFinders: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/cuteepeiarchu/PathFinders/resolve/main/backend/src/app.ts
- Command line
-
hf download hf://spaces/cuteepeiarchu/PathFinders/backend/src/app.ts
-
curl -L -o app.ts https://huggingface.co/spaces/cuteepeiarchu/PathFinders/resolve/main/backend/src/app.ts
1.03 kB
| import fs from "fs"; | |
| import path from "path"; | |
| import cors from "cors"; | |
| import express from "express"; | |
| import { env } from "./config/env"; | |
| import { errorHandler } from "./middlewares/errorHandler"; | |
| import { notFound } from "./middlewares/notFound"; | |
| import { apiRouter } from "./routes"; | |
| export const app = express(); | |
| app.use( | |
| cors({ | |
| origin: (origin, callback) => { | |
| if (!origin || !env.clientOrigin || env.clientOrigin === "*" || origin === env.clientOrigin) { | |
| callback(null, true); | |
| return; | |
| } | |
| callback(new Error("Origin not allowed by CORS.")); | |
| }, | |
| }), | |
| ); | |
| app.use(express.json()); | |
| app.use("/api", apiRouter); | |
| const frontendDistPath = path.resolve(__dirname, "..", "..", "frontend", "dist"); | |
| const frontendIndexPath = path.join(frontendDistPath, "index.html"); | |
| if (fs.existsSync(frontendIndexPath)) { | |
| app.use(express.static(frontendDistPath)); | |
| app.get(/^\/(?!api).*/, (_req, res) => { | |
| res.sendFile(frontendIndexPath); | |
| }); | |
| } | |
| app.use(notFound); | |
| app.use(errorHandler); | |