Add server for Railway deployment
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log*
|
||||||
|
.DS_Store
|
||||||
@@ -5,5 +5,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@primer/css": "17.0.1"
|
"@primer/css": "17.0.1"
|
||||||
},
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "node server.js"
|
||||||
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
36
server.js
Normal file
36
server.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
const http = require('http');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const PORT = process.env.PORT || 3000;
|
||||||
|
const HOST = '0.0.0.0';
|
||||||
|
|
||||||
|
const indexPath = path.join(__dirname, 'index.html');
|
||||||
|
|
||||||
|
const server = http.createServer((req, res) => {
|
||||||
|
if (req.url === '/health') {
|
||||||
|
const payload = { status: 'ok', service: 'demo' };
|
||||||
|
const body = JSON.stringify(payload);
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Content-Length': Buffer.byteLength(body)
|
||||||
|
});
|
||||||
|
res.end(body);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.readFile(indexPath, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
||||||
|
res.end('Internal Server Error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/html' });
|
||||||
|
res.end(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(PORT, HOST, () => {
|
||||||
|
console.log(`Server running at http://${HOST}:${PORT}`);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user