-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
81 lines (59 loc) · 1.89 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const mongoose = require('mongoose')
const express = require('express')
const cookieParser = require('cookie-parser');
const methodOverride = require('method-override');
var logger = require('morgan');
require('dotenv').config()
const app = express()
mongoose.connect(process.env.DATABASE_URL, { useNewUrlParser: true , useUnifiedTopology: true })
const db = mongoose.connection
db.on('error',(error)=> console.log(error))
db.once('open',()=> console.log('Successful connected to database'))
app.use(logger('dev'));
app.use(express.json())
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(methodOverride('_method'));
//Define views engine
app.set('views', './views');
app.set('view engine', 'pug');
//res.render('index');
const userRouter = require('./routes/canal')
app.use('/canal',userRouter)
const localRouter = require('./routes/FullRestFul')
app.use('/onlyRestFul',localRouter)
const welcomRouter = require('./routes/welcome')
app.use('/',welcomRouter)
const port = process.env.PORT
app.listen(port, () => console.log('Server Started on port:',port))
app.use(function(req, res, next){
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.render('404', { title: 'No encontrado' });
return;
}
// respond with json
if (req.accepts('json')) {
res.send({ error: 'Not found' });
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
app.use(function(req, res, next){
res.status(500);
// respond with html page
if (req.accepts('html')) {
res.render('500', { title: 'No encontrado' });
return;
}
// respond with json
if (req.accepts('json')) {
res.send({ error: 'Not found' });
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
module.exports = app;