-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (40 loc) · 1.24 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require('express');
const cors = require('cors');
const path = require('path');
require('dotenv').config({ path: '.env.local' });
const app = express();
const port = process.env.PORT || 3000;
app.use(cors({
origin: [
'http://localhost:8080',
'https://clyde.at'
],
methods: ['GET'],
credentials: true
}));
// // Serve static files from the Vue production build
// app.use(express.static(path.join(__dirname, 'dist')));
app.get('/download-resume', async (req, res) => {
try {
const response = await fetch(process.env.VUE_APP_RESUME_URL, {
headers: {
'Authorization': `Bearer ${process.env.VUE_APP_BLOB_READ_WRITE_TOKEN}`
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const arrayBuffer = await response.arrayBuffer();
res.setHeader('Content-Type', 'application/pdf');
res.send(Buffer.from(arrayBuffer));
} catch (err) {
res.status(500).send(`Failed to download resume: ${err.message}`);
}
});
// Handle all other routes by serving the Vue app
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});