-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (33 loc) · 1.16 KB
/
index.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
36
37
38
import express from 'express';
import cors from 'cors';
import winston from 'winston';
import clientsRouter from './routes/client.route.js';
import productsRouter from './routes/product.route.js';
import suppliersRouter from './routes/supplier.route.js';
import salesRouter from './routes/sale.route.js';
const { combine, timestamp, label, printf } = winston.format;
const myFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} [${label}] ${level} ${message}`;
});
global.logger = winston.createLogger({
level: 'silly',
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'store-api.log' }),
],
format: combine(label({ label: 'store-api' }), timestamp(), myFormat),
});
const app = express();
app.use(express.json());
app.use(cors());
app.use('/client', clientsRouter);
app.use('/product', productsRouter);
app.use('/supplier', suppliersRouter);
app.use('/sale', salesRouter);
app.use((err, req, res, next) => {
logger.error(`${req.method} ${req.baseUrl} - ${err.message}`);
res.status(400).send({ err: err.message });
});
app.listen(3000, () => {
console.log('App listening on port 3000!');
});