forked from app-generator/api-server-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (32 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
*
* Author: AppSeed.us - Full Stack App Generator
*
* License: MIT - Copyright (c) AppSeed.us
* @link https://github.com/rosoftdeveloper/appseed
*
*/
const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const cors = require('cors');
const models = require('./models');
/* Make all variables from our .env file available in our process */
require('dotenv').config();
/* Init express */
const app = express();
/* Here we setup the middlewares & configs */
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(session({ secret: process.env.SESSION_SECRET, cookie: { maxAge: 60000 }, resave: false, saveUninitialized: false }));
require('./config/passport');
/* Here we define the api routes */
app.use(require('./routes'));
const port = process.env.PORT || 3000;
const address = process.env.SERVER_ADDRESS || '127.0.0.1';
/* Create everything automatically with sequelize ORM */
models.sequelize.sync().then(function () {
app.listen( port, address, () => console.log(`Server running on http://${address}:${port}`));
});
module.exports = app;