-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
60 lines (49 loc) · 1.91 KB
/
index.ts
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
import express, { Request, Response } from "express";
import { render } from "./src/render";
import cors from "cors";
import axios from "axios";
import path from "path";
import fs from "fs";
import { getCurrentThemes } from "./src/themes";
const app = express();
app.use(cors());
app.use(express.static(path.join(__dirname, "frontend/dist")));
const PORT = process.env.PORT || 8080;
const HOST = process.env.DOCKER === "true" ? "0.0.0.0" : "localhost";
app.get(
"/api/render/:name/:headline/:currentPosition/:education/:theme/:profileImageUrl/",
async (req: Request, res: Response) => {
try {
let { name, headline, currentPosition, education, theme, profileImageUrl } = req.params;
if (getCurrentThemes().includes(theme) === false) {
throw new Error(`Theme ${theme} is not supported`);
}
// Link to base64
const image = await axios.get(profileImageUrl, { responseType: "arraybuffer" });
const base64Img = Buffer.from(image.data, "binary").toString("base64");
res.set("Content-Type", "image/svg+xml");
res.send(
render({
name,
headline,
currentPosition,
education,
profileImageUrl: base64Img,
theme,
})
);
} catch (err) {
res.status(400).send(err);
}
}
);
app.get("/api/getThemes", (req: Request, res: Response) => {
res.send(getCurrentThemes());
});
app.get("/", (req: Request, res: Response) => {
res.sendFile(__dirname, "frontend/dist/index.html");
});
app.listen(PORT, () => {
console.log(`Server running on http://${HOST}:${PORT}`);
});
// Link: https://badges.linkedin.com/profile?locale=en_US&badgetype=VERTICAL&badgetheme=light&uid=92175&version=v1&maxsize=medium&trk=profile-badge&vanityname=ivan