This commit is contained in:
Russell2259
2023-05-10 16:50:35 -06:00
+14 -7
View File
@@ -1,14 +1,21 @@
import express from 'express';
import * as url from 'url';
import * as path from 'node:path';
import { fileURLToPath } from 'url';
import { join } from 'node:path';
const app = express();
const port = process.env.port || 8080;
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const port = process.env.PORT || 8080;
const __dirname = fileURLToPath(new URL('.', import.meta.url));
app.use(express.static(path.join(__dirname, '/static'), { extensions: ['html'] }));
app.use((req, res) => res.status(404).sendFile(path.join(__dirname, './static/', '404.html')));
app.use(express.static(join(__dirname, '/static'), { extensions: ['html'] }));
app.use((req, res) => res.status(404).sendFile(join(__dirname, './static/', '404.html')));
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something broke!');
});
const server = app.listen(port, () => {
console.log(`Polaris is running on port ${server.address().port}, using nodejs ${process.version}`);
})
});