-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (34 loc) · 1.11 KB
/
server.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
37
38
39
40
41
42
const express = require('express');
const app = express();
const PORT = process.env.PORT || 5050;
const cors = require('cors');
//server set up with Express and Node, and to handle endpoints for transitions and scenes data. Did not need separate routes, as game only has two endpoints needed for data
app.use(cors({
origin: 'https://amiamistory.com'
}));
app.use(express.json());
const transitionsData = require('./data/transitions.json');
const scenesData = require('./data/scenes.json');
app.get('/', (_req, res) => {
console.log("get request I guess");
res.send("Hey, this server runs, cool");
});
app.get('/transitions', (_req, res) => {
try {
res.json(transitionsData);
} catch (error) {
console.error('Error fetching transitions:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
app.get('/scenes', (_req, res) => {
try {
res.json(scenesData);
} catch (error) {
console.error('Error fetching scenes:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});