-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
36 lines (27 loc) · 1.04 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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const Home = require('./home');
const config = require('./package.json').config;
const pug = require('pug');
const sanitizer = require('express-sanitizer');
let myHome = new Home(config.homeIP);
app.use(express.urlencoded({extended: true}));
app.set('view engine', 'pug')
app.locals.moment = require('moment');
app.get('/', (req, res) => {
res.render('partials/home', { messages : myHome.history })
});
app.post('/speak', (request, response) => {
myHome.speak(request.body.message, (homeResponse) => {
console.log(homeResponse);
});
response.redirect('/');
});
app.get('/readTweet/:id', (httpRequest, httpResponse) => {
myHome.readTweet(httpRequest.params.id, (homeResponse) => {
console.log(homeResponse);
httpResponse.render('layout', {messages: myHome.history});
});
});
app.listen(config.webServer.port, () => console.log('Now listening on port ' + config.webServer.port));