forked from lucadonnoh/artblocks-site-production
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
78 lines (67 loc) · 3.32 KB
/
server.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const path = require('path');
const express = require("express");
const app = express();
const fs = require('fs');
function isNumber(value) {
return isNaN(value) === false;
}
const pathToIndex = path.join(__dirname, 'build/index.html');
app.get('/token/:tokenId', (req, res) => {
const raw = fs.readFileSync(pathToIndex, "utf8");
const token = req.params.tokenId;
if (isNumber(token) === false) {
res.redirect("/token/0");
} else {
const updated1 = raw.replace('https://api.artblocks.io/image/248', (
`https://api.artblocks.io/image/${token}`));
const updated2 = updated1.replace('https://api.artblocks.io/image/248', (
`https://api.artblocks.io/image/${token}`));
const updated3 = updated2.replace('https://api.artblocks.io/image/248', (
`https://api.artblocks.io/image/${token}`));
const updated4 = updated3.replace('https://api.artblocks.io/image/248', (
`https://api.artblocks.io/image/${token}`));
res.send(updated4);
}
})
app.get('/project/:projectId', (req, res) => {
const raw = fs.readFileSync(pathToIndex, "utf8");
const project = req.params.projectId;
if (isNumber(project) === false) {
res.redirect("/project/0");
} else {
const updated1 = raw.replace('https://api.artblocks.io/image/248', (
`https://api.artblocks.io/image/${project * 1000000}`));
const updated2 = updated1.replace('https://api.artblocks.io/image/248', (
`https://api.artblocks.io/image/${project * 1000000}`));
const updated3 = updated2.replace('https://api.artblocks.io/image/248', (
`https://api.artblocks.io/image/${project * 1000000}`));
const updated4 = updated3.replace('https://api.artblocks.io/image/248', (
`https://api.artblocks.io/image/${project * 1000000}`));
res.send(updated4);
}
})
app.get('/sustainability', (req, res) => {
const raw = fs.readFileSync(pathToIndex, "utf8");
//const project = req.params.projectId;
/*if (isNumber(project) === false) {
res.redirect("/project/0");
} else {*/
const updated1 = raw.replace('https://api.artblocks.io/image/248', (
`https://lh3.googleusercontent.com/Pb95y9FbyRaibJ2qvm3AhiQ83xTDr98EGsJ6kGNZrSdLQ0EXZFRYS_5lwRhrL6_2q9D-Wo9WNE641LlUUHMlgld4loz5PQmrVfo2=s0`));
const updated2 = updated1.replace('https://api.artblocks.io/image/248', (
`https://lh3.googleusercontent.com/Pb95y9FbyRaibJ2qvm3AhiQ83xTDr98EGsJ6kGNZrSdLQ0EXZFRYS_5lwRhrL6_2q9D-Wo9WNE641LlUUHMlgld4loz5PQmrVfo2=s0`));
const updated3 = updated2.replace('https://api.artblocks.io/image/248', (
`https://lh3.googleusercontent.com/Pb95y9FbyRaibJ2qvm3AhiQ83xTDr98EGsJ6kGNZrSdLQ0EXZFRYS_5lwRhrL6_2q9D-Wo9WNE641LlUUHMlgld4loz5PQmrVfo2=s0`));
const updated4 = updated3.replace('https://api.artblocks.io/image/248', (
`https://lh3.googleusercontent.com/Pb95y9FbyRaibJ2qvm3AhiQ83xTDr98EGsJ6kGNZrSdLQ0EXZFRYS_5lwRhrL6_2q9D-Wo9WNE641LlUUHMlgld4loz5PQmrVfo2=s0`));
res.send(updated4);
//}
})
app.use(express.static(path.join(__dirname, "build")));
app.get("*", (req, res) =>
res.sendFile(path.join(__dirname, "build/index.html"))
);
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`Server started on port ${port}`);
})