-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguages.js
More file actions
53 lines (43 loc) · 1.67 KB
/
Copy pathlanguages.js
File metadata and controls
53 lines (43 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import express from 'express';
import cors from 'cors';
import helmet from 'helmet';
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
import config from './config.js';
import apiRouter from './routes/index.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Ensure workspace + upload dirs exist
fs.mkdirSync(config.workspaceRoot, { recursive: true });
const UPLOAD_DIR = path.resolve(__dirname, '../uploads');
fs.mkdirSync(UPLOAD_DIR, { recursive: true });
const app = express();
app.use(helmet({
contentSecurityPolicy: false,
crossOriginResourcePolicy: { policy: 'cross-origin' }
}));
app.use(cors());
app.use(express.json({ limit: '25mb' }));
app.use(express.urlencoded({ extended: true }));
// Static uploads (optional for previewing)
app.use('/uploads', express.static(UPLOAD_DIR));
// API routes
app.use('/api', apiRouter);
// Serve built React client in production
const clientDist = path.resolve(__dirname, '../client/dist');
if (fs.existsSync(clientDist)) {
app.use(express.static(clientDist));
app.get(/^(?!\/api).*/, (req, res) => res.sendFile(path.join(clientDist, 'index.html')));
}
// Health + info
app.get('/api/health', (req, res) => res.json({ ok: true, app: 'VibeDev', version: '1.0.0', time: new Date().toISOString() }));
// Error handler
app.use((err, req, res, next) => {
console.error(err);
res.status(err.status || 500).json({ error: err.message || 'Internal error' });
});
app.listen(config.port, () => {
console.log(`\n ⚡ VibeDev running → http://localhost:${config.port}`);
console.log(` AI provider: ${config.ai.activeProvider}`);
console.log(` Workspace: ${config.workspaceRoot}\n`);
});