mirror of https://github.com/aruppi/aruppi-api.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
989 B
TypeScript
42 lines
989 B
TypeScript
import express, { Application } from 'express';
|
|
import cors from 'cors';
|
|
import helmet from 'helmet';
|
|
import dotenv from 'dotenv';
|
|
import { errorHandler, notFound } from './middlewares/middleware';
|
|
import {
|
|
createConnectionMongo,
|
|
} from './database/connection';
|
|
import routes from './routes';
|
|
|
|
const app: Application = express();
|
|
|
|
dotenv.config();
|
|
createConnectionMongo({
|
|
host: process.env.DATABASE_HOST,
|
|
port: process.env.DATABASE_PORT,
|
|
});
|
|
app.use(cors());
|
|
app.use(helmet());
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: false }));
|
|
app.use(routes);
|
|
app.use(notFound);
|
|
app.use(errorHandler);
|
|
|
|
/*
|
|
Starting the server on the .env process
|
|
you can define the PORT where the server
|
|
is going to listen in the server.
|
|
ex: PORT=3000.
|
|
*/
|
|
const server = app.listen(process.env.PORT_LISTEN || 3000);
|
|
|
|
function shutdown(): void {
|
|
server.close();
|
|
process.exit();
|
|
}
|
|
|
|
process.on('SIGINT', shutdown);
|
|
process.on('SIGQUIT', shutdown);
|
|
process.on('SIGTERM', shutdown);
|