-
Notifications
You must be signed in to change notification settings - Fork 4
/
route.js
78 lines (65 loc) · 2.38 KB
/
route.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 express = require("express");
const path = require("path");
const fs = require("fs");
const https = require("https");
const app = express.Router();
app.get("*", (request, response, next) => {
// console.log("utf8", request.path);
const filePath = path.resolve(__dirname, "./build", "index.html");
fs.readFile(filePath, "utf8", function (err, data) {
if (request.path.startsWith("/topic")) {
// console.log(request.path.startsWith("/topic"));
// console.log(request.path);
let baseurl = "https://api.libraa.ml/media/";
const topicname = request.path.split("/")[2];
const topic = topicname.split("_")[1]
const meta =
request.path.split("/")[6] === undefined
? "meta description"
: request.path.split("/")[6];
const image = request.path.split("/")[7];
url = baseurl + image.replaceAll("%7C", "/");
// console.log(url);
// console.log(topic);
// console.log(meta);
// let img = "";
// let imgSvg = "";
// if (request.path) {
// img = baseurl + url.split("svg")[0] + "png";
// imgSvg = baseurl + url;
// }
// var buffers = [];
// function href2base64(img) {
// return new Promise(function (resolve, reject) {
// https.get(img).on("response", function (r) {
// r.on("data", function (data) {
// buffers.push(data);
// }).on("end", function () {
// resolve(
// `data:${r.headers["content-type"]};base64,${Buffer.concat(
// buffers
// ).toString("base64")}`
// );
// });
// });
// });
// }
// fs.readFile(buffers, function(err, data) {
// var base64data = new Buffer(data).toString('base64');
// console.log(base64data)
// });
data = data
.replace("<title>React App</title>", `<title>${topic}</title>`)
.replace("__META_OG_TITLE__", topic)
.replace("__META_OG_DESCRIPTION__", meta)
.replace("__META_DESCRIPTION__", meta)
.replace("__META_OG_IMAGE__", url);
// .replace(
// "__META_OG_IMAGE__",
// "https://api.libraa.ml/media/Users/logo192.png"
// );
response.send(data);
}
});
});
module.exports = app;