-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (49 loc) · 1.61 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
59
60
61
62
63
var express = require('express');
var compression = require('compression')
var krautipsum = require('./src/krautipsum');
var kraut = require('kraut');
var KrautBot = require('krautbot');
var app = express();
var cors = require('cors');
var router = express.Router();
app.set('port', (process.env.PORT || 5000));
app.use(compression());
app.use(express.static(__dirname + '/dist'));
app.use(cors());
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.get('/', function(request, response) {
krautipsum(function(error, paragraph) {
response.render('pages/index', { paragraph: paragraph });
});
});
// API stuff ---------------------------------------------
router.get('/kraut', function(req, res) {
krautipsum(function(error, paragraph) {
res.json({ kraut: paragraph });
});
});
router.get('/sentence', function(req, res) {
res.json({ sentence: kraut.ipsum.makeSentence() });
});
router.get('/greeting', function(req, res) {
res.json({ greeting: kraut.greetings.random() });
});
router.get('/adjective', function(req, res) {
res.json({ adjective: kraut.adjectives.random() });
});
router.get('/noun', function(req, res) {
res.json({ noun: kraut.nouns.random() });
});
router.get('/verb', function(req, res) {
res.json({ verb: kraut.verbs.random() });
});
// REGISTER OUR API ROUTES -------------------------------
// all of our routes will be prefixed with /api
app.use('/api', router);
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
// KRAUTBOT
const krautBot = new KrautBot();
krautBot.start();