-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
43 lines (38 loc) · 1.4 KB
/
main.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
var express = require("express"),
connect = require("connect"),
http = require("http"),
logger = require("./lib/logger")(__filename),
allowCrossDomain = require("./lib/allow-cross-domain"),
dataStore = require("./lib/data-store").create(),
services = require("./lib/services")(dataStore),
stations = require("./lib/stations"),
logos = require("./lib/logos"),
stream = require("./lib/stream")(dataStore),
authName = process.env.BASIC_AUTH || false,
port = (process.env.PORT || 5000),
server = module.exports = express();
server.configure(function() {
if(authName != false) {
server.use(connect.basicAuth(authName, authName));
}
server.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
server.use(connect.methodOverride());
server.use(connect.urlencoded());
server.use(connect.json());
server.use(allowCrossDomain);
server.use(server.router);
server.use(connect.static("public"));
});
server.get("/", function(req, res) {
res.send("<h1>BBC Radio Services API</h1>");
res.end();
});
server.get("/services.json", services);
server.get("/stations.json", stations);
server.get("/logos.json", logos);
server.get("/stream", stream);
http.createServer(server).listen(port);
logger.info("Started server on port", port);