-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (28 loc) · 1.04 KB
/
app.js
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
const express = require('express');
const userRouter = require('./src/routes/userRouter');
const workspaceRouter = require('./src/routes/workspaceRouter');
const loginRouter = require('./src/routes/loginRouter');
const channelRouter = require('./src/routes/channelRouter');
const messageRouter = require('./src/routes/mesageRouter');
const AppError = require('./src/utils/AppError');
const app = express();
app.use(express.json({ limit: '10kb' }));
// Test Middleware
app.use((req, res, next) => {
console.log('Hello from middleware');
next();
});
app.use((req, res, next) => {
req.requestTime = new Date().toISOString();
console.log(`The request was hit at ${req.requestTime}`);
next();
});
app.use('/api/v1/auth', loginRouter);
app.use('/api/v1/workspaces', workspaceRouter);
app.use('/api/v1/channels', channelRouter);
app.use('/api/v1/users', userRouter);
// app.use('/api/v1/messages', messageRouter);
app.all('*', (req, res, next) => {
next(new AppError(`Can't find ${req.originalUrl} on this server!`, 404));
});
module.exports = app;