{"size": 837, "ext": "js", "max_stars_repo_path": "src/app.js", "max_stars_repo_name": "CabralArthur/boilerplate-node", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/app.js", "max_issues_repo_name": "CabralArthur/boilerplate-node", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/app.js", "max_forks_repo_name": "CabralArthur/boilerplate-node", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.925, "max_line_length": 69, "alphanum_fraction": 0.623655914}
import http from 'http';
import cors from 'cors';
import dotenv from 'dotenv';
import helmet from 'helmet';
import express from 'express';

import * as Logger from './utils/logger';

const setup = app => {
	app.use(cors());
	app.use(helmet());
	app.use(express.json({ limit: '100000kb' }));
	app.use(express.urlencoded({ extended: false, limit: '100000kb' }));

	app.use((error, req, res, next) => {
		if (error) {
			res.status(500).json({
				status: 'error',
				message: 'Algo de errado aconteceu'
			});
			return;
		}

		next();
	});
};

export const start = () => {
	dotenv.config({ path: `${__dirname}/../.env` });

	const app = express();
	const port = process.env.PORT || 3000;
	const httpServer = http.createServer(app);

	httpServer.listen(port, () => {
		Logger.success(`Server running port ${port}`);
		setup(app);
	});
};
