Repository navigation
Expand file tree
/
Copy pathrender-server.mjs
More file actions
100 lines (87 loc) · 3.45 KB
/
Copy pathrender-server.mjs
File metadata and controls
100 lines (87 loc) · 3.45 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (c) 2026 iTVT Poland Group / ReVideeo Authors
* Licensed under the European Union Public Licence v1.2 (EUPL-1.2)
* See LICENSE file in the project root for full license information.
*/
import express from 'express';
import { loadConfig } from './modules/config.mjs';
import { initAI } from './modules/ai.mjs';
import { initBundle, registerRenderRoutes } from './modules/render.mjs';
import { registerJuicerRoutes } from './modules/juicer.mjs';
import { registerPluginRoutes } from './modules/plugins.mjs';
import { registerSpaceRenderRoutes } from './modules/space-render.mjs';
import { registerTranscriptionRoutes } from './modules/transcribe.mjs';
const start = async () => {
const config = await loadConfig();
config.aiEnabled = config.aiProvider !== 'disabled' && (
config.aiProvider === 'gemini' ? !!config.aiApiKey
: config.aiProvider === 'custom' ? !!config.aiEndpoint
: config.aiPower > 0
);
const app = express();
const allowedOrigins = [
'http://localhost:5173',
'http://localhost:4173',
'http://127.0.0.1:5173',
'http://127.0.0.1:4173',
'http://[::1]:5173',
'http://[::1]:4173',
'https://revideeo.app',
'https://project-97xly.vercel.app',
];
const extraOrigins = (process.env.CORS_EXTRA_ORIGINS ?? '').split(',').map((s) => s.trim()).filter(Boolean);
allowedOrigins.push(...extraOrigins);
const isAllowedOrigin = (origin) => {
if (!origin) return true;
if (allowedOrigins.some((o) => origin.startsWith(o))) return true;
if (/^https:\/\/revideeo-[a-z0-9]+(-[a-z0-9]+)*\.vercel\.app$/.test(origin)) return true;
return false;
};
app.use((req, res, next) => {
const origin = req.headers.origin;
if (isAllowedOrigin(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin || '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, Access-Control-Request-Private-Network');
res.setHeader('Access-Control-Allow-Credentials', 'true');
}
if (req.method === 'OPTIONS' && req.headers['access-control-request-private-network']) {
res.setHeader('Access-Control-Allow-Private-Network', 'true');
}
if (req.method === 'OPTIONS') {
return res.sendStatus(204);
}
next();
});
app.use(express.json({ limit: '8gb' }));
await registerPluginRoutes(app);
await registerSpaceRenderRoutes(app, config);
registerRenderRoutes(app, config);
registerJuicerRoutes(app, config);
registerTranscriptionRoutes(app);
app.get('/api/health', (_req, res) => {
res.json({
ok: true,
ready: true,
modules: { 'space-render': config.spaceRenderEnabled, 'server-plugins': true, 'juicer': config.aiEnabled, 'render': config.renderEnabled },
ai: { provider: config.aiProvider, power: config.aiPower, enabled: config.aiEnabled },
});
});
await initAI(config);
if (config.renderEnabled) {
await initBundle(config.entry, config.chromiumExecutable, config.chromiumArgs, config.timeoutMs);
} else {
console.log('[render-server] rendering DISABLED (modules.render=false)');
}
app.listen(config.port, '0.0.0.0', () => {
console.log(`[render-server] listening on http://0.0.0.0:${config.port}`);
});
};
start().catch((err) => {
console.error('[render-server] failed to start:', err);
process.exit(1);
});
process.on('SIGINT', () => {
console.log('\n\n server closed\n');
process.exit(0);
});