-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
64 lines (53 loc) · 1.47 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
57
58
59
60
61
62
63
64
'use strict'
/*
* Dependencias
*/
const express = require('express')
const expresSession = require('express-session')
const http = require('http')
const bodyParser = require('body-parser')
const methodOverride = require('method-override')
const mongoose = require('mongoose')
const routerApp = require("./routerApp");
const authSession = require('./middlewares/session')
const UserCtrl = require('./controlers/User')
const app = express()
const server = http.Server(app)
const routerAuth = express.Router()
/*
* Use middlewares
*/
app.use('/public', express.static('public'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
//app.use(sessionMiddlewareRedis)
app.use(methodOverride('_method'))
/*
* Iniciando Server
*/
console.log('------------------------------')
console.log('----------Iniciando-----------');
console.log('------------------------------')
// conect BD
mongoose.connect('mongodb://localhost/api-photo', (err,res) => {
if(err) res.status(500).json({error:true, message:err.message})
console.log('Connect to Database')
})
/*
* Enrutamineto
*/
// route Auth
routerAuth.route('/login')
.post(UserCtrl.login)
routerAuth.route('/signup')
.post(UserCtrl.add)
// Route Basic user
routerAuth.route('/')
.get((req,res) => {
res.status(200).json({message:'Hola client'})
})
app.use('/api',routerAuth)
app.use('/api/app', authSession.ensureAuthenticated)
app.use('/api/app',routerApp)
server.listen(8000)
module.exports = server