UNCLASSIFIED - NO CUI

Skip to content
Snippets Groups Projects
Verified Commit e3d044d3 authored by Patrick Tafoya's avatar Patrick Tafoya
Browse files

template fixes

parent b0ba5c5e
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,13 @@ const express = require('express');
const app = express();
const port = 8000;
// This middleware logs every incoming request with the current timestamp, HTTP method, and URL path.
app.use((req, res, next) => {
const timestamp = new Date().toISOString();
console.log(`[${timestamp}] ${req.method} ${req.originalUrl}`);
next();
});
app.get('/', (req, res) => {
res.send('Hello World! at /');
});
......@@ -12,6 +19,21 @@ app.get('/api/', (req, res) => {
res.send('Hello World! at /api/');
});
// This route handles all other paths not previously defined.
// It ensures that any undefined route still returns a 200 status with the path accessed.
app.all('*', (req, res) => {
res.status(200).send(`Hello World! at ${req.path}`);
});
// This middleware catches any errors that occur in the request-processing pipeline.
// It logs the error details and sends a 500 Internal Server Error response.
app.use((err, req, res, next) => {
const timestamp = new Date().toISOString();
console.error(`[${timestamp}] Error: ${err.message}`);
console.error(err.stack);
res.status(500).send('Internal Server Error');
});
app.listen(port, () => {
console.log(`App is running at http://localhost:${port}`);
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment