- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
Latest commit
36 lines (30 loc) · 1.09 KB
/
Copy pathserver.js
File metadata and controls
36 lines (30 loc) · 1.09 KB
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
/**
* purpose: proxy to get original high res images from drive. doesn't do anything unless u run server.js
* to run this:
* install node.js + dependencies (express and node-fetch)
* run server locally w/ server.js
* server is on localhost:3000
* to use proxy in HTML, change image urls from https://drive.google.com/thumbnail?id=FILE_ID to http://localhost:3000/FILE_ID
*/
constexpress=require('express');
constfetch=require('node-fetch');
constapp=express();
constPORT=process.env.PORT||3000;
app.get('/:fileId',async(req,res)=>{
const{ fileId }=req.params;
consturl=`https://drive.google.com/uc?export=download&id=${fileId}`;
try{
constresponse=awaitfetch(url);
if(!response.ok){
returnres.status(404).send('Image not found');
}
res.setHeader('Content-Type',response.headers.get('content-type'));
response.body.pipe(res);
}catch(error){
console.error('Error fetching image:',error);
res.status(500).send('Internal Server Error');
}
});
app.listen(PORT,()=>{
console.log(`Proxy server running on port ${PORT}`);
});