-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapi.js
More file actions
36 lines (26 loc) · 787 Bytes
/
api.js
File metadata and controls
36 lines (26 loc) · 787 Bytes
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 db = require("./db/transactions.json");
const user = require("./db/user.json");
const bodyParser = require("body-parser");
const port = 3000;
const app = express();
app.use(bodyParser.json());
app.get("/health-check", (_, res) => {
return res.sendStatus(200);
});
app.post("/auth", (req, res) => {
const { cpf, password } = req.body;
if (cpf === user.cpf && password === user.password)
return res.status(200).json({
token: user.token,
});
return res.sendStatus(401);
});
app.get("/list", (req, res) => {
const token = req.headers.token;
if (!token || token === user.token) return res.sendStatus(401);
return res.json(db);
});
app.listen(port, () => {
console.log(`[api] running on port \`${port}\``);
});