Download src/server.ts from nexusbert/zurri: direct link, hf CLI and curl.
- Browser
- Download file 2.75 kB
-
https://huggingface.co/spaces/nexusbert/zurri/resolve/main/src/server.ts
- Command line
-
hf download hf://spaces/nexusbert/zurri/src/server.ts
-
curl -L -o server.ts https://huggingface.co/spaces/nexusbert/zurri/resolve/main/src/server.ts
2.75 kB
| const isHuggingFaceSpace = !!process.env.HF_SPACE_ID || !!process.env.SPACE_ID; | |
| const isProduction = process.env.NODE_ENV === 'production'; | |
| if (!isHuggingFaceSpace && !isProduction) { | |
| const dotenv = require('dotenv'); | |
| const path = require('path'); | |
| const fs = require('fs'); | |
| const envPath = path.join(__dirname, '../.env'); | |
| if (fs.existsSync(envPath)) { | |
| dotenv.config({ path: envPath }); | |
| console.log(`π Development: Loaded .env from: ${envPath}`); | |
| } else { | |
| dotenv.config(); | |
| console.log('π Development: Using default .env location'); | |
| } | |
| } else { | |
| console.log('π Production: Using environment variables from platform secrets'); | |
| } | |
| import 'reflect-metadata'; | |
| import { AppDataSource } from './config/database'; | |
| import app from './app'; | |
| import { initializeAdmin } from './scripts/createAdmin'; | |
| const PORT = parseInt(process.env.PORT || process.env.SPACE_PORT || '7860', 10); | |
| console.log('π§ Starting server...'); | |
| console.log(`π‘ Environment: ${process.env.NODE_ENV || 'development'}`); | |
| console.log(`π Port: ${PORT}`); | |
| if (process.env.DATABASE_URL) { | |
| const dbUrl = process.env.DATABASE_URL; | |
| const masked = dbUrl.length > 60 | |
| ? `${dbUrl.substring(0, 30)}...${dbUrl.substring(dbUrl.length - 10)}` | |
| : dbUrl; | |
| console.log(`π Database URL: Set (${masked})`); | |
| } else { | |
| console.log(`π Database URL: β NOT SET`); | |
| } | |
| AppDataSource.initialize() | |
| .then(async () => { | |
| console.log('β Database connected'); | |
| if (process.env.DB_SYNCHRONIZE !== 'true' && process.env.NODE_ENV === 'production') { | |
| try { | |
| console.log('π Running migrations...'); | |
| await AppDataSource.runMigrations(); | |
| console.log('β Migrations completed'); | |
| } catch (migrationError) { | |
| console.warn('β οΈ Migration warning:', migrationError); | |
| } | |
| } | |
| // Initialize permanent admin user from environment variables | |
| await initializeAdmin(); | |
| app.listen(PORT, '0.0.0.0', () => { | |
| console.log(`π Server running on port ${PORT}`); | |
| console.log(`π Server accessible at http://0.0.0.0:${PORT}`); | |
| console.log(`π Swagger docs available at http://0.0.0.0:${PORT}/docs`); | |
| console.log(`β€οΈ Health check at http://0.0.0.0:${PORT}/health`); | |
| }); | |
| }) | |
| .catch((error) => { | |
| console.error('β Database connection failed:', error); | |
| console.error('Error details:', error.message); | |
| process.exit(1); | |
| }); | |
| // Graceful shutdown | |
| process.on('SIGTERM', async () => { | |
| console.log('SIGTERM received, closing server...'); | |
| await AppDataSource.destroy(); | |
| process.exit(0); | |
| }); | |
| process.on('SIGINT', async () => { | |
| console.log('SIGINT received, closing server...'); | |
| await AppDataSource.destroy(); | |
| process.exit(0); | |
| }); | |