Download server/src/app.ts from Nhut0902/freelmapi: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/Nhut0902/freelmapi/resolve/main/server/src/app.ts
- Command line
-
hf download hf://spaces/Nhut0902/freelmapi/server/src/app.ts
-
curl -L -o app.ts https://huggingface.co/spaces/Nhut0902/freelmapi/resolve/main/server/src/app.ts
1.43 kB
| import express from 'express'; | |
| import cors from 'cors'; | |
| import helmet from 'helmet'; | |
| import path from 'path'; | |
| import { fileURLToPath } from 'url'; | |
| import { keysRouter } from './routes/keys.js'; | |
| import { modelsRouter } from './routes/models.js'; | |
| import { proxyRouter } from './routes/proxy.js'; | |
| import { fallbackRouter } from './routes/fallback.js'; | |
| import { analyticsRouter } from './routes/analytics.js'; | |
| import { healthRouter } from './routes/health.js'; | |
| import { settingsRouter } from './routes/settings.js'; | |
| import { errorHandler } from './middleware/errorHandler.js'; | |
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | |
| export function createApp() { | |
| const app = express(); | |
| app.use(cors()); | |
| app.use( | |
| helmet({ | |
| contentSecurityPolicy: false, | |
| }), | |
| ); | |
| app.use(express.json({ limit: '10mb' })); | |
| // API routes | |
| app.use('/v1/keys', keysRouter); | |
| app.use('/v1/models', modelsRouter); | |
| app.use('/v1/chat/completions', proxyRouter); | |
| app.use('/v1/fallback', fallbackRouter); | |
| app.use('/v1/analytics', analyticsRouter); | |
| app.use('/health', healthRouter); | |
| app.use('/settings', settingsRouter); | |
| // Frontend | |
| app.use(express.static(path.join(process.cwd(), 'client/dist'))); | |
| // SPA fallback | |
| app.get(/^\/(?!v1|health|settings).*/, (_, res) => { | |
| res.sendFile(path.join(process.cwd(), 'client/dist/index.html')); | |
| }); | |
| // Error handler | |
| app.use(errorHandler); | |
| return app; | |
| } |