-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
47 lines (42 loc) · 1.28 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
/* express set up */
var express = require('express');
var app = express();
app.engine('.html', require('ejs').__express);
app.set('views', __dirname);
app.set('view engine', 'html');
/* MarkLogic set up */
var marklogic = require("marklogic")
var conn = require("./env.js").connection
var db = marklogic.createDatabaseClient(conn)
var q = marklogic.queryBuilder
/* use Express as http server */
app.use('/public', express.static(__dirname+'/public'));
app.get('/data', function(req, res) {
// query database for documents to be shown
// use localhost:3000/data?collection=***
var name = req.param('collection') || 'addr.json';
var query = db.documents.query(q.where(q.collection(name)));
query.result(function(r){
// get result and log all uris
console.log("GET DOCS from collection =",name);
console.log("result =");
for (i=0; i<r.length; i++)
console.log(r[i].uri);
return r;
}).
then(function(r){
// send json back to http response
console.log("rendering....");
res.json(r);
});
});
app.get('/delete', function(req, res) {
// delete temporal document
// TODO add your code here...
});
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
});
/* start listening */
app.listen(3000);
console.log('listening on port 3000');