-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (33 loc) · 1.01 KB
/
index.js
File metadata and controls
40 lines (33 loc) · 1.01 KB
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
import express from 'express';
import dotenv from 'dotenv';
import cors from 'cors';
import bodyParser from 'body-parser';
import { errorMiddleware, notFoundMiddleware } from './middleware/errorMiddleware.js';
import http from 'http';
import wsHandler from './wsHandler.js';
import welcomeRoutes from './routes/welcomeRoutes.js';
import authRoutes from './routes/authRoutes.js';
import friendRoutes from './routes/friendRoutes.js';
import chatRoutes from './routes/chatRoutes.js';
const app = express();
const server = http.Server(app);
const ws = wsHandler(server);
dotenv.config();
//middlewares
app.use(cors());
app.use(express.static('public'));
app.use(bodyParser.json());
//routes
app.use('/', welcomeRoutes);
app.use('/auth', authRoutes);
app.use('/friend', friendRoutes);
app.use('/chat', chatRoutes);
//error middlewares
app.use(errorMiddleware);
app.use(notFoundMiddleware);
//listen socket.io
ws.listen();
//serve
server.listen(process.env.PORT, () => {
console.log(`Server started on *:${process.env.PORT}`);
});