-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (45 loc) · 1.43 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require("express");
const cors = require("cors");
const app = express();
const port = 3000;
app.use(cors());
app.use(express.static("views"));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/views/home.html");
});
app.get("/docs", (req, res) => {
res.sendFile(__dirname + "/views/docs.html");
});
const { quotes, kataBijak, newObject, quoteSteveJobs, tagSteveJobs } = require("./src/lib/data");
app.get("/api", (req, res) => {
res.json(newObject);
});
app.get("/api/quote", (req, res) => {
const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
const no = Math.floor(Math.random() * quotes.length);
res.json({ no: no, quotes: randomQuote });
});
app.get("/api/quote/stevejobs", (req, res) => {
const randomQuoteSteve = quoteSteveJobs[Math.floor(Math.random() * quoteSteveJobs.length)];
const no = Math.floor(Math.random() * quoteSteveJobs.length);
const tag = tagSteveJobs
res.json({
no: no,
quotes: randomQuoteSteve,
tag: tag
})
})
app.get("/api/katabijak", (req, res) => {
const randomBijak = kataBijak[Math.floor(Math.random() * kataBijak.length)];
const no = Math.floor(Math.random() * kataBijak.length);
res.json({ no: no, katabijak: randomBijak });
});
app.listen(port, (err, res) => {
if (err) {
console.log(err);
return res.status(500).send(err.message);
} else {
console.log(`[INFO] server is running on port: ${port}`);
}
});
module.exports = app;