Skip to content

Commit 208f065

Browse files
committed
Update webserver logic
1 parent aec2361 commit 208f065

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

node-express-server/webserver.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ app.use((req, res, next) => {
1818
});
1919

2020
app.get('/', (req, res) => {
21+
const userAgent = new UserAgents().toString();
2122
res.status(200).json({ message: 'Hello Express!' }); // Respond with JSON
22-
console.log(`Received GET request to the API with userAgent:`);
23-
console.log(userAgent.toString());
23+
console.log(`Received GET request to the API with userAgent: ${userAgent}`);
2424
});
2525

2626
app.post('/', (req, res) => {
@@ -30,23 +30,23 @@ app.post('/', (req, res) => {
3030

3131
app.put('/user', (req, res) => {
3232
try {
33+
const userAgent = new UserAgents().toString();
3334
// Ensure the request body is parsed and simulate an error if requested
3435
if (req.body && req.body.simulateError) {
3536
throw new Error('Simulated server error');
3637
}
3738
res.status(200).json({ message: 'Resource updated successfully' });
38-
console.log(`Received PUT request from port: ${port} to ${dir}userAgent:`);
39-
console.log(userAgent.toString());
39+
console.log(`Received PUT request from port: ${port} to ${dir} userAgent: ${userAgent}`);
4040
} catch (error) {
4141
res.status(500).json({ error: 'Internal server error' }); // Handle server error
4242
console.error('Error occurred on PUT /user:', error.message);
4343
}
4444
});
4545

4646
app.delete('/user', (req, res) => {
47+
const userAgent = new UserAgents().toString();
4748
res.status(204).send(); // Respond with 204 for successful deletion
48-
console.log(`Received DELETE request from port: ${port} to ${dir}userAgent:`);
49-
console.log(userAgent.toString());
49+
console.log(`Received DELETE request from port: ${port} to ${dir} userAgent: ${userAgent}`);
5050
});
5151

5252
// POST /user route

0 commit comments

Comments
 (0)