-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (22 loc) · 1023 Bytes
/
Copy pathindex.js
File metadata and controls
27 lines (22 loc) · 1023 Bytes
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 cors = require("cors");
const axios = require("axios");
const app = express();
app.use(cors({origin: "*", methods: ["GET"]}));
app.options("*", (req, res) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.sendStatus(200);
});
app.get("/fetch-pdf/:id", async (req, res) => {
const fileUrl = `https://drive.google.com/uc?export=download&id=${req.params.id}`;
const response = await axios.get(fileUrl, {responseType: "arraybuffer"});
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.setHeader("Content-Disposition", "inline")
res.setHeader("Content-Type", "application/pdf");
res.send(response.data);
});
app.listen(3000, () => console.log("Proxy running on port 3000"));