-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (54 loc) · 2.11 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
58
const fs = require("fs");
const Web3 = require("web3");
const http = require("http");
const url = 'https://rpc.ankr.com/eth_rinkeby'
const port = process.env.PORT || 8000;
const server = http.createServer((req, res) => {
const readstream = fs.createReadStream("./index.html");
if (req.url == "/node_modules/web3/dist/web3.min.js") {
fs.readFile("./node_modules/web3/dist/web3.min.js", "utf8", (err, file) => {
if (err) {
console.log(err);
} else {
res.write(file);
res.end();
}
});
} else if (req.url == "/node_modules/web3/dist/web3.min.js.map") {
fs.readFile("./node_modules/web3/dist/web3.min.js.map", "utf8", (err, file) => {
if (err) {
console.log(err);
} else {
res.write(file);
res.end();
}
});
} else if (req.url == "/") {
res.writeHead(200, { "Content-type": "text/html" });
readstream.pipe(res);
} else if (req.url == "/bitcoin_header.svg") {
var img = fs.readFileSync('./bitcoin_header.svg');
res.writeHead(200, { "Content-type": "image/svg+xml" });
res.end(img, "binary");
} else if (req.url == "/cryptopredictlogo2.png") {
var img = fs.readFileSync('./cryptopredictlogo2.png');
res.writeHead(200, { "Content-type": "image/png" });
res.end(img, "binary");
} else if (req.url == "/cryptopredictlogo.png") {
var img = fs.readFileSync('./cryptopredictlogo.png');
res.writeHead(200, { "Content-type": "image/png" });
res.end(img, "binary");
} else if (req.url == "/favicon.png") {
var img = fs.readFileSync('./favicon.png');
res.writeHead(200, { "Content-type": "image/png" });
res.end(img, "binary");
} else if (req.url == "/avax" || req.url == "/bnb" || req.url == "/eth") {
res.write("More cryptocurrencies are coming soon!");
res.end();
} else {
res.write("Oops. This page does not exist!");
res.end();
}
});
console.log("Server started!");
server.listen(port);