forked from Go-phie/gophie-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
148 lines (137 loc) · 4.42 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const express = require("express");
const morgan = require("morgan");
const app = express();
const port = process.env.PORT || 3000;
const path = require("path");
const fs = require("fs");
const axios = require("axios");
const rfs = require("rotating-file-stream");
const filePath = path.resolve(__dirname, "./build", "index.html");
// Log into separate files every day
const accessLogStream = rfs.createStream("access.log", {
interval: "1d",
path: path.join(__dirname, "log"),
});
// use dev mode for console logging
app.use(morgan("dev"));
// use full mode for stored logs
app.use(
morgan(
':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version"' +
':status :res[content-length] :response-time ms ":referrer" ":user-agent"',
{ stream: accessLogStream }
)
);
app.get("/", (request, response) => {
let result = null;
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
return console.log(err);
}
// edit links for link preview
data = data.replace(/\$OG_TITLE/g, "Gophie");
data = data.replace(
/\$OG_DESCRIPTION/g,
"Search, stream and download movies, series and anime without bumping into a single ad on your favourite movie aggregator site"
);
result = data.replace(
/\$OG_IMAGE/g,
"https://res.cloudinary.com/silva/image/upload/v1587376155/goophie-meta-banner.png"
);
response.send(result);
});
});
app.get("/shared/:referralID", (request, response) => {
const referralID = request.params.referralID;
let result = null;
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
return console.log(err);
}
axios
.post(
`https://gophie-ocena.herokuapp.com/referral/id/?referral_id=${referralID}`
)
.then((json) => {
let movie_name = json.data.name;
let description = json.data.description;
let image = json.data.cover_photo_link;
data = data.replace(/\$OG_TITLE/g, `Gophie - ${movie_name}`);
if (description.length <= 1) {
description = "Could not find movie description";
}
if (image.length <= 1) {
image =
"https://res.cloudinary.com/silva/image/upload/v1587376155/goophie-meta-banner.png";
}
data = data.replace(/\$OG_DESCRIPTION/g, description);
result = data.replace(/\$OG_IMAGE/g, image);
response.send(result);
})
.catch((error) => {
console.log("Could not retrieve movie details", error);
response.redirect("/");
});
});
});
app.get("/terms", (request, response) => {
let result = null;
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
return console.log(err);
}
// edit links for link preview
data = data.replace(/\$OG_TITLE/g, "Gophie");
data = data.replace(/\$OG_DESCRIPTION/g, "Terms and Conditions of Usage");
result = data.replace(
/\$OG_IMAGE/g,
"https://res.cloudinary.com/silva/image/upload/v1587376155/goophie-meta-banner.png"
);
response.send(result);
});
});
app.get("/:engine", (request, response) => {
const engine = request.params.engine;
let result,
description = null;
switch (engine) {
case "Server2":
case "Server7":
description = "Download your favourite anime for free with a simple click";
break;
case "Server4":
description =
"Download TV series for free with a simple click of the button";
break;
case "Server3":
description =
"Download Hollywood, Bollywood HD Movies with a simple click of the button";
break;
default:
description = "Download Movies with a simple click of the button";
break;
}
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
return console.log(err);
}
// edit links for link preview
data = data.replace(/\$OG_TITLE/g, `Gophie - ${engine}`);
data = data.replace(/\$OG_DESCRIPTION/g, description);
result = data.replace(
/\$OG_IMAGE/g,
"https://res.cloudinary.com/silva/image/upload/v1587376155/goophie-meta-banner.png"
);
response.send(result);
});
});
app.use(express.static(path.resolve(__dirname, "./build")));
app.get("*", (request, response) => {
response.sendFile(filePath);
});
app.listen(port, () => console.log(`Listening on port ${port}`));
// app.get("/search/:search_term", (request, response) => {
// const data = request.params.page
// console.log("here")
// response.send(data);
// });