-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheocatserver.js
64 lines (54 loc) · 1.93 KB
/
eocatserver.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 version = "v1.0";
var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');
var child_process = require('child_process');
var products = require('./routes/catalogue');
var bodyParser = require('body-parser');
var app = express();
var expressWs = require('express-ws');
var protocol = (process.argv[2])?process.argv[2]:'http';
var port = (process.argv[3])?process.argv[3]:'3000';
app.use(bodyParser.json({limit:10000000}));
app.use(express.static('public'));
/*
app.use(function (req, res, next) {
console.log('middleware');
return next();
});
*/
var server;
if(protocol == 'https') {
try {
var credentials = {
key: fs.readFileSync('./ssl/key.pem'),
cert: fs.readFileSync('./ssl/cert.pem'),
rejectUnauthorized: false
};
}
catch (err) {
console.log("ERROR: EOCat server not started (Could not read the server key or certificate in the ./ssl folder)");
process.exit(1);
}
server = https.createServer(credentials, app);
expressWs(app,server);
server.listen(port, function() {console.log("EOCat "+version+" is listening HTTPS on port "+port+"...");});
} else {
server = http.createServer(app);
expressWs(app,server);
server.listen(port, function() {console.log("EOCat "+version+" is listening HTTP on port "+port+"...");});
}
//app.get('/products', products.findAll);
app.get('/:dataset/search', products.search);
app.get('/odata/products', products.odata);
app.get('/harvestOADS', products.harvestOADS);
app.ws('/harvestDHUS', products.harvestDHUS);
app.ws('/harvestDHUSQuery', products.harvestDHUSQuery);
app.get('/products/:id', products.findById);
app.post('/products', products.addProduct);
app.post('/ngEOproducts', products.addProductFromNgEO);
app.post('/hubProducts', products.addProductFromHub);
app.put('/products/:id', products.updateProduct);
app.delete('/products/:id', products.deleteProduct);
app.get('/describe', products.describe);