-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (46 loc) · 1.48 KB
/
server.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const express = require('express')
var bodyParser = require('body-parser')
const db = require('./model/db.js')
var user_routes = require('./routes/user_routes.js')
var user_controller = require('./controller/user_controller')
var https = require('https')
var fs = require('fs')
const cors = require('cors');
const cookieParser = require('cookie-parser');
var deck_routes = require('./routes/deck_routes.js')
var battle_routes = require('./routes/battle_routes.js')
var trade_routes = require('./routes/trade_routes.js')
require('dotenv').config();
var app = express()
const port = 3000;//porta sulla quale sarà in ascolto il server
//middleware
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
app.use(cookieParser())
app.use(cors())
app.use(express.static('public'))
app.set('view engine', 'ejs')
//##############################################
//sezione routes
app.use(user_routes)
app.use(deck_routes)
app.use(battle_routes)
app.use(trade_routes)
//app.get('/', function(req, res){res.send('hello')})
https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.cert')
}, app).listen(port, function()
{
console.log("App listening on --> " + port)
//appena viene aperto il servero ccorre connettersi al db
//altrimenti dovrei connettermi ogni volta che voglio fare una query
db.connection.connect(function(err)
{
if(err)
console.log("Cannot connect to db --> " + err)
else
console.log("Connected to db")
})
})
exports.app = app