StMarkSchoolApplication / app.js
app.js
Raw
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json())

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, course_id, X-Requested-With, x-access-token, Content-Type, Accept");
  next();
});

require('./app/router/router.js')(app);

const db = require('./app/config/db.config.js');

const adminRouter = require('./app/router/admin.router.js')(db)
app.use('/admin', adminRouter)

const Role = db.role;

// force: true will drop the table if it already exists
db.sequelize.sync({ force: false }).then(() => {
  console.log('Drop and Resync with { force: false }');
  //initial();
});

// Create a Server
var server = app.listen(process.env.PORT || 8080, function () {

  var host = server.address().address
  var port = server.address().port

  console.log("App listening at http://%s:%s", host, port)
})

// function initial(){
// 	Role.create({
// 		id: 1,
// 		name: "STUDENT"
// 	});

// 	Role.create({
// 		id: 2,
// 		name: "INSTRUCTOR"
// 	});

// 	Role.create({
// 		id: 3,
// 		name: "ADMIN"
// 	});
// }