ChatRooms/index.js

27 lines
659 B
JavaScript
Raw Normal View History

2023-01-16 13:13:04 +00:00
const fs = require('fs');
const http = require('http');
const express = require('express');
const app = express();
2023-01-16 13:30:44 +00:00
const clientPath = __dirname+'/../html';
2023-01-16 13:40:33 +00:00
console.log('Serving static from ' + clientPath);
2023-01-16 14:21:30 +00:00
app.use(express.json());
2023-01-16 13:13:04 +00:00
app.use(express.static(clientPath));
const server = http.createServer(app);
2023-01-16 13:30:44 +00:00
app.post('/message', (req, res) => {
2023-01-16 14:21:30 +00:00
const { user, message } = req.body;
res.status(200).json({message});
2023-01-16 13:30:44 +00:00
});
2023-01-16 13:13:04 +00:00
server.on('error', err => {
2023-01-16 14:21:30 +00:00
console.error('Internal server error', err);
2023-01-16 13:13:04 +00:00
});
server.on('close', () => {
console.log("Shutting down ...");
});
server.listen(3000, () => {
2023-01-16 13:40:33 +00:00
console.log('Server running on port 3000');
2023-01-16 13:13:04 +00:00
});