-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-server.js
More file actions
43 lines (34 loc) · 979 Bytes
/
simple-server.js
File metadata and controls
43 lines (34 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const PORT = 3001;
// Middleware
app.use(cors());
app.use(bodyParser.json());
// Log endpoint
app.post('/api/log', (req, res) => {
const { type, message, details } = req.body;
// Format the log message
const timestamp = new Date().toISOString();
// Log to terminal
console.log(`[${timestamp}] [${type}] ${message}`);
if (details) {
console.log('Details:', details);
}
res.status(200).json({ success: true });
});
// Test endpoint
app.get('/api/test', (req, res) => {
console.log('Test endpoint called');
res.json({ message: 'Server is working' });
});
// Home page
app.get('/', (req, res) => {
res.send('Logging server is running');
});
// Start the server
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
console.log('Navigation events will be logged here in the terminal');
});