Created
December 26, 2016 06:40
-
-
Save Rafi993/38e9a8b78bffd2d52ac28dd889ee9527 to your computer and use it in GitHub Desktop.
porting to expressjs from sailsjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let app = require('express')(), | |
connect = require('connect'), | |
bodyParser = require('body-parser'), | |
cors = require('cors'), | |
commandLineArgs = require('command-line-args'); | |
const port = 1337; | |
const optionDefinitions = [ | |
{ name:'port', alias:'p', type:Number, defaultOption: true ,defaultValue : 1337 } | |
] | |
const options = commandLineArgs(optionDefinitions) | |
const policies = require('./config/policies').policies; | |
const models = require('./config/connection'); | |
app.use(cors(require('./config/cors').getcors())); | |
// global variables | |
app.set('port',options.port); | |
app.set('boot',true); | |
app.use(bodyParser.json()) | |
require('./config/bootstrap')(app); | |
require('./config/globals')(app); | |
models.waterline.initialize(models.config, (err, models) => { | |
if(err) throw err; | |
app.models = models.collections; | |
app.connections = models.connections; | |
app.use(policies); | |
require('./config/routes')(app); | |
require('./config/error')(app); | |
require('./config/middleware')(app); | |
// console.log('controllers list: ', app.get('controller')) | |
app.listen(app.get('port'), () => { | |
console.log("App is running in", app.get('port')) | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment