-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (31 loc) · 1.09 KB
/
index.js
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
const express = require('express');
const app = express();
const path = require('path');
const fetch = require('node-fetch');
require('dotenv').config();
const port = process.env.PORT || 3000;
app.set('view engine', 'ejs');
// Serve static files (CSS, JS)
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', async (req, res) => {
try {
const apiUrl = process.env.API_URL;
const response = await fetch(`${apiUrl}/recent-release?type=1&page=1`);
const recentSubs = await response.json();
const responseDub = await fetch(`${apiUrl}/recent-release?type=2&page=1`);
const recentDubs = await responseDub.json();
res.render('index', {
websiteTitle: process.env.WEBSITE_TITLE,
websiteUrl: process.env.WEBSITE_URL,
banner: process.env.BANNER_URL,
version: process.env.VERSION,
recentSubs,
recentDubs
});
} catch (error) {
res.status(500).send('Error fetching data');
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});