-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
48 lines (40 loc) · 1.56 KB
/
app.js
File metadata and controls
48 lines (40 loc) · 1.56 KB
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
var express = require('express');
var app = express(),
station = require('./src/routes/station');
var winston = require('winston');
var async = require('async');
var utils = require('./src/lib/utils');
var defaults = require('./config/defaults');
var overrides = require('./config/overrides');
if (!process.env.NODE_ENV) {
throw new Error("NODE_ENV not set");
}
config = utils.merge(defaults, overrides);
var winstonStream = {
write: function(message, encoding){
winston.info(message.slice(0, -1));
}
};
winston.add(winston.transports.File, { filename: './log/api.log' });
app.use(express.logger({stream:winstonStream}));
app.use(express.compress());
app.configure(function() {
app.all('*', function(request, response, next) {
response.header('Access-Control-Allow-Origin', '*');
response.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
response.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}),
// app.use(express.static('public'));
app.use('/public', express.static(__dirname + '/public'));
});
app.get('/api/station/:id', station.getAllMetrics);
app.get('/api/station/:id/swh', station.getSignificantWaveHeight);
//app.get('/api/station/:id/wwh', station.getWindWaveHeight);
//app.get('/api/station/:id/swp', station.getSignificantWavePeriod);
//app.get('/api/station/:id/apd', station.getAverageWavePeriod);
app.listen(config.api.port);
console.log("Loaded configuration: " );
utils.pp(config);
console.log('Listening on port ' + config.api.port);
module.exports = app;