-
Notifications
You must be signed in to change notification settings - Fork 7
/
wordplay-app.js
68 lines (50 loc) · 1.55 KB
/
wordplay-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
64
/*
WordPlay Server (node.js)
The Office For Creative Research
May, 2014
https://github.com/blprnt/wordplay
*/
var express = require('express')
require('express')
, stylus = require('stylus')
, nib = require('nib')
, marked = require('marked')
var app = express();
//CONFIGURE JADE, NIB, STYLUS
function compile(str, path) {
return stylus(str)
.set('filename', path)
.use(nib())
}
app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.use(stylus.middleware(
{ src: __dirname + '/public'
, compile: compile
}
))
app.use(express.static(__dirname + '/public'))
//PAGE SERVING
app.get('/', function (req, res) {
res.render('index',
{ title : 'Simple, free-text linguistic search' }
)
})
app.get('/:corpus/:input', function (req, res) {
res.render('index',
{ title : 'Simple, free-text linguistic search', defCorpus: req.params.corpus, defInput: req.params.input }
)
})
//API CALLS
app.get('/wp/:corpus/:input/:max', function(req, res){
//res.send('Process ' + req.params.input + ' from ' + req.params.corpus);
res.send(JSON.stringify(require('wordplay.js').getWordMatches(req.params.input, req.params.corpus, req.params.max)), null, 4);
});
app.get('/wp/:corpus/:input', function(req, res){
//res.send('Process ' + req.params.input + ' from ' + req.params.corpus);
res.send(JSON.stringify(require('wordplay.js').getWordMatches(req.params.input, req.params.corpus, 20)), null, 4);
});
//START IT UP.
var server = app.listen(12892, function() {
console.log('Listening on port %d', server.address().port);
});