-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
37 lines (30 loc) · 959 Bytes
/
app.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
var http = require('http');
var express = require('express');
var poweredBy = require('poweredby');
var morgan = require('morgan');
var errorHandler = require('./lib/errorHandler');
var authOyster = require('./lib/authOyster');
var app = express();
app.set('port', process.env.PORT || 3000);
app.use(poweredBy('Slow Crawly Things'));
app.use(morgan('dev'));
app.get('/', function(req, res, next) {
res.redirect('https://github.com/bencevans/oyster-api');
});
app.get('/valid_auth', authOyster, function(req, res) {
res.send({ valid_auth: true });
});
app.get('/balance', authOyster, function(req, res) {
req.oyster.balance(function(err, balance) {
if(err) {
return next(err);
}
res.send({
balance: parseFloat(balance)
});
});
});
app.use(errorHandler);
http.createServer(app).listen(app.get('port'), function() {
console.log('Oyster API listening on port ' + app.get('port'));
});