forked from give-india/frontend-developer-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
27 lines (22 loc) · 787 Bytes
/
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
const express = require("express");
const http = require("http");
const app = express();
const compression = require("compression");
const path = require("path");
const YOUTUBE_META_URL = "http://www.youtube.com/oembed?format=json&url=";
app.use(compression());
app.get("/api/youtubeMeta", async (req, res) => {
http.get(`${YOUTUBE_META_URL}${req.query.url}`, youtubeMetaRes => {
youtubeMetaRes.on("data", buffer => {
let data = Buffer.from(buffer);
res.json(data.toString());
});
});
});
// Serve the static files from the React app
app.use(express.static(path.join(__dirname, "/build")));
// Handles any requests that don't match the ones above
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname + "/build/index.html"));
});
app.listen(1234);