feat(Countries): Adding countries endpoint
This commit is contained in:
49
index.js
49
index.js
@@ -1,8 +1,9 @@
|
||||
'use strict';
|
||||
const express = require('express');
|
||||
require('dotenv').config();
|
||||
const { ROOT_PATH , LIB_PATH } = process.env;
|
||||
const { ROOT_PATH, LIB_PATH, API_CONFIG } = process.env;
|
||||
const apiConfig = require( `${ROOT_PATH}/${API_CONFIG}` );
|
||||
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const compression = require('compression');
|
||||
const morgan = require('morgan');
|
||||
@@ -10,12 +11,20 @@ const helmet = require('helmet');
|
||||
const bodyParser = require('body-parser');
|
||||
const fileUpload = require('express-fileupload');
|
||||
const sections = require('./sections/sections.js');
|
||||
const middleWares = require( `${ROOT_PATH}/${LIB_PATH}/Middlewares.js` );
|
||||
const middlewares = require( `${ROOT_PATH}/${LIB_PATH}/Middlewares.js` );
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
mongoose.connect(
|
||||
apiConfig.mongodb,
|
||||
{ useNewUrlParser: true }
|
||||
).then( ( val ) => {
|
||||
console.log( "MongoDB Connected" );
|
||||
});//catch throw error so service stops!
|
||||
|
||||
const app = express();
|
||||
const serverPort = process.env.SERVER_PORT || 3000;
|
||||
|
||||
app.use( middleWares.Auth );
|
||||
app.use( middlewares.Auth );
|
||||
app.use(
|
||||
fileUpload({
|
||||
limits: { fileSize: 4 * 1024 * 1024 },
|
||||
@@ -39,24 +48,24 @@ app.use(morgan('dev'));
|
||||
app.use(helmet());
|
||||
app.use(compression());
|
||||
app.use(cors({
|
||||
origin: '*',
|
||||
methods: [
|
||||
'GET',
|
||||
'POST',
|
||||
'PATCH',
|
||||
'PUT',
|
||||
'DELETE'
|
||||
],
|
||||
allowedHeaders: ['Content-Type', 'Authorization']
|
||||
origin: '*',
|
||||
methods: [
|
||||
'GET',
|
||||
'POST',
|
||||
'PATCH',
|
||||
'PUT',
|
||||
'DELETE'
|
||||
],
|
||||
allowedHeaders: ['Content-Type', 'Authorization']
|
||||
}));
|
||||
app.use( middleWares.errorJSON );
|
||||
app.use( middlewares.errorJSON );
|
||||
app.use( sections );
|
||||
app.use( middleWares.error404 );
|
||||
app.use( middlewares.error404 );
|
||||
|
||||
app.listen( serverPort , function(err){
|
||||
if( !err ){
|
||||
console.log('API listen on port', serverPort );
|
||||
}else{
|
||||
console.log( err );
|
||||
}
|
||||
if( !err ){
|
||||
console.log('API listen on port', serverPort );
|
||||
}else{
|
||||
console.log( err );
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user