-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFederator.js
90 lines (74 loc) · 2.18 KB
/
Federator.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
80
81
82
83
84
85
86
87
88
89
90
/*
* Simple NodeJS Implementation of EIDA Federator
*
* Copyright Mathijs Koymans, 2016
*
* Only supports GET requests.
*
* Dataselect allowed parameters:
* >>> Network, Station, Location, Channel, Starttime & Endtime
*
* Station allowed parameters:
* >>> Network, Station, Location, Channel, Starttime & Endtime
* >>> latitude, longitude, minradius, maxradius
* >>> minlatitude, maxlatitude, minlongitude, maxlontigude
*
* WFCatalog allowed parametes:
* >>> net(work), sta(tion), loc(ation), cha(nnel), start(time) & end(time)
* >>> include
*
*/
"use strict";
// Federator is powered by NodeJS Express
const Federator = require("express")();
const CONFIG = require("./Config");
// Wrap the federator in a module
module.exports = function(federatorCallback) {
/*
* Require the Federator Routes:
* WFCatalog is currently not implemented in routing
*
* |--routes
* |--version
* |--application.wadl
* |--dataselect
* |--query
* |--application.wadl
* |--wfcatalog
* |--query
* |--application.wadl
* |-- station
* |--query
* |--application.wadl
*
*/
// Default request handler
require("./routes")(Federator);
// Require the paths
require("./routes/version")(Federator);
require("./routes/application.wadl")(Federator);
// Query implementations
require("./routes/dataselect/query")(Federator);
require("./routes/station/query")(Federator);
require("./routes/wfcatalog/query")(Federator);
// Require the .wadls
require("./routes/dataselect/application.wadl")(Federator);
require("./routes/station/application.wadl")(Federator);
require("./routes/wfcatalog/application.wadl")(Federator);
// Listen to incoming HTTP requests
var server = Federator.listen(CONFIG.PORT, CONFIG.HOST, function() {
// If a callback function was passed
if(federatorCallback instanceof Function) {
federatorCallback("NodeJS Federator has been started");
}
});
// Disable server timeouts
server.timeout = CONFIG.FEDERATOR_TIMEOUT;
}
// Called directly
if(require.main === module) {
// Start a single federator
new module.exports(function(message) {
console.log(message);
});
}