-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
24 lines (20 loc) · 783 Bytes
/
app.js
File metadata and controls
24 lines (20 loc) · 783 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
require('dotenv').config()
const http = require('node:http');
const BitcoinController = require('./controller')
const hostname = '0.0.0.0';
const port = process.env.PORT || 8080;
const bitcoinController = new BitcoinController()
const server = http.createServer(async (req, res) => {
if (req.url === "/api/bitcoin" && req.method === "GET") {
const bitcoin = await bitcoinController.get();
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify(bitcoin));
}
else {
res.writeHead(404, { "Content-Type": "application/json" });
res.end(JSON.stringify({ message: "Route not found" }));
}
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});