This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/backend/app.js

27 lines
919 B
JavaScript
Raw Normal View History

2020-03-16 22:55:32 +01:00
/* Modules */
const express = require('express');
const helmet = require('helmet');
const cors = require('cors');
const morgan = require('morgan');
2020-03-16 22:55:32 +01:00
/* Files Imports & Variables */
const { PORT } = require('./assets/config/config');
const { serverError } = require('./assets/config/errors');
const sendResponse = require('./assets/utils/sendResponse');
const app = express();
2020-03-16 22:55:32 +01:00
/* Middlewares */
app.use(helmet());
2020-03-16 22:55:32 +01:00
app.use(cors());
app.use(morgan('dev'));
app.use(express.json());
/* Routes */
app.use('/functions', require('./routes/functions'));
/* Errors Handling */
app.use((_req, res, _next) => sendResponse(res, { result: "La route n'existe pas!", httpStatus: 404 })); // 404
app.use((error, _req, res, _next) => { console.log(error); return sendResponse(res, serverError); }); // 500
2020-03-16 22:55:32 +01:00
/* Server */
app.listen(PORT, () => console.log('\x1b[36m%s\x1b[0m', `Started on port ${PORT}.`));