-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (44 loc) · 1.52 KB
/
app.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
const CosmosClient = require('@azure/cosmos').CosmosClient;
const config = require('./config');
const Tasklist = require('./routes/tasklist');
const Task = require('./models/task');
const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const TaskList = require('./routes/tasklist');
const app = express();
// Mostrar los views de JADE como HTML con EXPRESS
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
const cosmosClient = new CosmosClient({
enspoint: config.host,
key: config.authKey,
});
const taskObjecto = new Task(cosmosClient, config.databaseID, config.containerID);
const taskList = new TaskList(taskObjeto);
taskObjecto
.init(err=> {
console.log(err);
})
.catch(err => {
console.log(err);
process.exit(1);
})
app.get("/", (req, res, next) => taskList.showTasks(req,res).catch(next));
app.post("/agrgar", (req,res,next)=>taskList.addTask(req,res).catch(next));
app.post("/completar", (req,res,next)=>taskList.completeTask(req,res).catch(next));
app.set('view engine', 'jade');
// Manejar un 404
app.use(function(req,res,next){
const error = new Error('No encontrado');
err.status = 404;
next(err);
});
module.exports = app;