-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaintest.js
61 lines (48 loc) · 1.64 KB
/
maintest.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import express, {json} from "express";
import cors from 'cors';
import welcomeData from './welcome.js'
import dotenv from 'dotenv';
//fetcher import
import { fetchAnimeMovies, fetchPopularAnime, fetchRecentReleased, fetchnewSeason } from "./Fetcher/fetchAnimeList.js";
import handleFetchingListRoutes from "./Routes/handleFetchingListRoutes.js";
import handleFetchingInfoRoutes from "./Routes/handleFetchingInfoRoutes.js";
dotenv.config();
const PORT = process.env.PORT || 3000;
const corsOptions = {
origin: '*', // Allow requests from any origin
credentials: true, // Allow credentials like cookies
optionSuccessStatus: 200,
port: PORT, // Set the port for CORS
};
const app = express();
app.use(cors(corsOptions));
app.use(json());
app.get('/', async (req, res) => {
try {
res.status(200).json(welcomeData);
} catch (err) {
res.status(500).json({
status: 500,
error: 'Internal Error',
message: err,
});
}
});
app.get('/recent-released', async (request,reply) =>{
handleFetchingListRoutes(request, reply, fetchRecentReleased);
});
app.get('/new-season', async (request,reply) =>{
handleFetchingListRoutes(request, reply, fetchnewSeason);
});
app.get('/popular', async (request,reply) =>{
handleFetchingListRoutes(request, reply, fetchPopularAnime);
});
app.get('/animemovies', async (request,reply) =>{
handleFetchingListRoutes(request, reply, fetchAnimeMovies);
});
app.get('/info/:animeId', async(request,reply)=>{
handleFetchingInfoRoutes(request, reply);
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});