-
-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathindex.ts
More file actions
75 lines (60 loc) · 2 KB
/
Copy pathindex.ts
File metadata and controls
75 lines (60 loc) · 2 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
import express from "express";
import session from "express-session";
import expressLayouts from "express-ejs-layouts";
import path from "path";
import fs from "fs";
import config from "../config.js";
import logger from "../utils/logger.js";
import { stringify, prettySize } from "./utils/helpers.js";
// Import middleware
import { requireAuth } from "./middleware/auth.js";
// Import route handlers
import authRoutes from "./routes/auth.js";
import dashboardRoutes from "./routes/dashboard.js";
import uploadRoutes from "./routes/upload.js";
import previewRoutes from "./routes/preview.js";
const app: express.Application = express();
// Configure EJS templating engine
app.set('view engine', 'ejs');
app.set('views', path.join(process.cwd(), 'src/server/views'));
// Use express-ejs-layouts
app.use(expressLayouts);
app.set('layout', 'layouts/main');
// Middleware
app.use(express.urlencoded({ extended: true }));
app.use(session({
secret: 'streambot-2024',
resave: false,
saveUninitialized: true,
cookie: { secure: process.env.NODE_ENV === 'production' }
}));
// Serve static files from public directory
app.use(express.static(path.join(process.cwd(), 'src/server/public')));
// Make helper functions available to all templates
app.use((req, res, next) => {
res.locals.stringify = stringify;
res.locals.prettySize = prettySize;
next();
});
// Apply authentication middleware to all routes except login
app.use(requireAuth);
// Routes
app.use('/', authRoutes);
app.use('/', dashboardRoutes);
app.use('/', uploadRoutes);
app.use('/', previewRoutes);
// Create necessary directories
if (!fs.existsSync(config.videosDir)) {
fs.mkdirSync(config.videosDir);
}
if (!fs.existsSync(path.dirname(config.previewCacheDir))) {
fs.mkdirSync(path.dirname(config.previewCacheDir), { recursive: true });
}
if (!fs.existsSync(config.previewCacheDir)) {
fs.mkdirSync(config.previewCacheDir);
}
// Start server
app.listen(config.server_port, () => {
logger.info(`Server is running on port ${config.server_port}`);
});
export default app;