-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (31 loc) · 898 Bytes
/
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
const express = require('express');
const oDataServer = require('simple-odata-server');
const Adapter = require('simple-odata-server-mongodb')
const app = express();
const port = 3000;
const url = 'mongodb://localhost:27017'
const mongo = require('mongodb').MongoClient;
var model = {
namespace: "test",
entityTypes: {
"listType": {
"_id": {"type": "Edm.String", key: true},
"name": {"type": "Edm.String"},
}
},
entitySets: {
"list": {
entityType: "listType"
}
}
};
var odataServer = oDataServer().model(model);
mongo.connect(url, function(err, db) {
odataServer.adapter(Adapter(function(cb) {
cb(err, db.db('test'));
}));
})
app.use("/odata", function(req, res) {
odataServer.handle(req, res);
})
app.listen(port, () => console.log('listening on port ${port}'))