-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
79 lines (63 loc) · 1.87 KB
/
server.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var express = require('express');
var app = express();
var SharePoint = require('./lib/sharepoint');
var config = require('./config');
///This builds our sharepoint config object from a config file. There are many different ways to go
///about doing this, using a config file was easiest for this example.
var buildSharePoint = function(){
var sp = new SharePoint({
site: config.site,
user: config.user,
pass: config.password
});
return sp;
}
//server setup
app.use('/', express.static(__dirname + '/example'));
//example routes
/*
Gets all the lists from the sharepoint site.
*/
app.get('/getAllLists', function(req, res){
var sp = buildSharePoint();
sp.getAllLists(['Title', 'ItemCount', 'Id']).then(function(result){
res.send(result);
}, function(err){
res.send(500, err);
});
});
/*
Gets all the list info for the given list name. req.query.list is the list name in this case.
*/
app.get('/getListInfo', function(req, res){
var list = req.query.list;
var sp = buildSharePoint();
sp.getListInfo(list).then(function(result){
res.send(result);
}, function(err){
res.send(500, err);
});
});
/*
Gets all the list info for the given list name. req.query.list is the list name in this case.
*/
app.get('/getListItems', function(req, res){
var list = req.query.list;
var sp = buildSharePoint();
sp.getListItems(list, ['Title']).then(function(result){
res.send(result);
}, function(err){
res.send(500, err);
});
});
app.get('/getListContentTypes', function(req, res){
var list = req.query.list;
var sp = buildSharePoint();
sp.getContentTypes(list, ['Name', 'StringId']).then(function(result){
res.send(result);
}, function(err){
res.send(500, err);
});
});
app.listen(3000);
console.log('Server listering at port 3000');