-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
43 lines (33 loc) · 1.16 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
37
38
39
40
41
42
43
const express = require("express");
const fs = require("fs");
const path = require("path");
const cors = require("cors"); // Import the cors package
const app = express();
// Use CORS middleware
app.use(cors());
// Serve static files from the 'public' directory
app.use(express.static(path.join(__dirname, "public")));
// Read JSON files
const vocaloids = JSON.parse(fs.readFileSync(path.join(__dirname, "json/vocaloids.json"), "utf-8"));
const mikuTimeLine = JSON.parse(fs.readFileSync(path.join(__dirname, "json/mikuTimeLine.json"), "utf-8"));
const mikuFacts = JSON.parse(fs.readFileSync(path.join(__dirname, "json/mikuFacts.json"), "utf-8"));
// Create GET requests
app.get("/", (req, res) => {
res.send("up and running! Welcome to the Miku API. Read docs on how to use: https://github.com/LeahJKH/MikuApiGithub");
});
// Get json files
app.get("/vocaloids", (req, res) => {
res.json(vocaloids);
});
app.get("/mikuTimeLine", (req, res) => {
res.json(mikuTimeLine);
});
app.get("/mikuFacts", (req, res) => {
res.json(mikuFacts);
});
// Get json files
// Initialize server
app.listen(8001, () => {
console.log("Running on port 8001.");
});
module.exports = app;