rajamaniraja
8/24/2019 - 7:39 AM

app.js

const express = require('express');
const bodyParser = require('body-parser');
const helmet = require('helmet');
const log4js = require('log4js');
const cors = require('cors');
const appLogger = log4js.getLogger();
const { initDbConnection } = require('./dbutil');
const { signUpController } = require('./controller')
// Express app instance
const app = express();

// helmet for security purpose
app.use(helmet());

// Logging Http Request

app.use(log4js.connectLogger(appLogger));

// CORS - To hanlde cross origin requests
app.use(cors());

// Parsing the body of the http

app.use((req, res, next) => {
	bodyParser.json({
		limit: '50mb',
		verify: (req, res, buf, encoding) => {
			req.rawBody = buf.toString();
		}
	})(req, res, err => {
		if (err) {
			res.status(400).send('Bad body Request');
			return;
		}
		next();
	});
});

app.use(bodyParser.urlencoded({
	limit: '50mb',
	extended: true
}));

//here we assign connection object to the global js object
global.clientConnection = db.initClientDbConnection();

global.appRoot = path.resolve(__dirname);

// our first signup route

app.post('/api/v1/signup',signUpController);

app.listen(3000, () => {
    logger.info(`Application running at PORT 3000`);
});