forked from sdamico/pitch-deck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.js
More file actions
51 lines (46 loc) · 1.4 KB
/
dev-server.js
File metadata and controls
51 lines (46 loc) · 1.4 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const http = require('http');
const fs = require('fs');
const path = require('path');
const MIME = {
'.html': 'text/html; charset=utf-8',
'.css': 'text/css',
'.js': 'application/javascript',
'.json': 'application/json',
'.woff': 'font/woff',
'.woff2': 'font/woff2',
'.ttf': 'font/ttf',
'.otf': 'font/otf',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.png': 'image/png',
'.webp': 'image/webp',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.mp4': 'video/mp4',
};
const server = http.createServer((req, res) => {
const url = req.url.split('?')[0];
let filePath;
if (url === '/' || url === '/index.html') {
filePath = path.join(__dirname, 'content', 'page.html');
} else if (url === '/platform-strategy-deck' || url === '/platform-strategy-deck.html') {
filePath = path.join(__dirname, 'content', 'platform-strategy-deck.html');
} else {
filePath = path.join(__dirname, 'public', url);
}
const ext = path.extname(filePath).toLowerCase();
const contentType = MIME[ext] || 'application/octet-stream';
fs.readFile(filePath, (err, data) => {
if (err) {
res.writeHead(404);
res.end('Not found');
return;
}
res.writeHead(200, { 'Content-Type': contentType });
res.end(data);
});
});
const PORT = parseInt(process.env.PORT, 10) || 3334;
server.listen(PORT, () => {
console.log('Pitch dev server running at http://localhost:' + PORT);
});