-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
53 lines (48 loc) · 1.3 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
49
50
51
52
53
const express = require('express');
const app = express();
const path = require('path');
const fs = require('fs');
const cors = require('cors');
app.use(cors());
// Serve JPEG image
app.get('/headshot', (req, res) => {
const filePath = path.join(__dirname, 'Headshot.jpg');
res.setHeader('Content-Type', 'image/jpeg');
fs.readFile(filePath, (err, data) => {
if (err) {
console.error(`Error reading file: ${err}`);
res.status(404).send('File not found');
} else {
res.send(data);
}
});
});
// Serve PDF
app.get('/resume', (req, res) => {
const filePath = path.join(__dirname, 'JosephBuck.pdf');
res.setHeader('Content-Type', 'application/pdf');
fs.readFile(filePath, (err, data) => {
if (err) {
console.error(`Error reading file: ${err}`);
res.status(404).send('File not found');
} else {
res.send(data);
}
});
});
// Serve Text
app.get('/text', (req, res) => {
const filePath = path.join(__dirname, 'text.txt');
res.setHeader('Content-Type', 'text/plain');
fs.readFile(filePath, (err, data) => {
if (err) {
console.error(`Error reading file: ${err}`);
res.status(404).send('File not found');
} else {
res.send(data.toString());
}
});
});
app.listen(3000, () => {
console.log('Server started on port 3000');
});