forked from ubershmekel/redditp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (25 loc) · 882 Bytes
/
server.js
File metadata and controls
33 lines (25 loc) · 882 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
28
29
30
31
32
33
// RedditP Node.js server with proper static file handling
var http = require('http');
var path = require('path');
var express = require('express');
var app = express();
app.set('port', process.env.PORT || 8080);
// CRITICAL: Static files MUST be registered BEFORE the catch-all route
const publicFolders = [
'.well-known',
'css',
'images',
'js'
];
// Serve static files - no special config needed, let Express handle it
for (let name of publicFolders) {
app.use('/' + name, express.static(path.join(__dirname, name)));
}
// Catch-all route for the SPA - this MUST come AFTER static routes
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'index.html'));
});
var server = http.createServer(app);
server.listen(app.get('port'), function () {
console.log("RedditP server listening at: http://localhost:" + app.get('port'));
});