UNCLASSIFIED - NO CUI
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fiesta-wagon-hello-express
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform One
Party Bus
fiesta-wagon
hello-world-templates
fiesta-wagon-hello-express
Commits
e3d044d3
Verified
Commit
e3d044d3
authored
5 months ago
by
Patrick Tafoya
Browse files
Options
Downloads
Patches
Plain Diff
template fixes
parent
b0ba5c5e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app.js
+22
-0
22 additions, 0 deletions
app.js
with
22 additions
and
0 deletions
app.js
+
22
−
0
View file @
e3d044d3
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment