Skip to content

Commit

Permalink
Merge branch 'release/v0.0.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
schlpbch committed Jun 29, 2017
2 parents 2dbb6fa + 846c0f4 commit 61796ed
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 169 deletions.
6 changes: 3 additions & 3 deletions api/controllers/bookings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ function confirm (req, res) {
},
'fulfil': {
title: 'Get ticket in PDF format',
href: 'api/bookings/3001/fulfil?type=pdf'
href: '../api/bookings/3001/fulfil?type=pdf'
},
'cancel': {
title: 'Cancel the booking',
href: 'api/bookings/3001/cancel'
href: '../api/bookings/3001/cancel'
},
'refund': {
title: 'Refund the booking',
href: 'api/bookings/3001/refund'
href: '../api/bookings/3001/refund'
}
}
}]
Expand Down
6 changes: 4 additions & 2 deletions api/controllers/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module.exports = {

function status (req, res) {
let now = new Date()
// TODO: distinguish between the version of the API and its implementation
let version = '0.0.12'
// TODO:
// - return a real JSON object
// - distinguish between the version of the API and its implementation
let version = '0.0.14'
res.json("{ status: 'ok', date: '" + now + "', version: '" + version + "'}")
}
8 changes: 4 additions & 4 deletions api/controllers/offers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ function offers (req, res) {
qualityOfService: '2nd',
_links: {
'self': {
href: 'offers/1001'
href: '../api/offers/1001'
},
'prebook': {
title: 'Book offer',
href: 'api/offers/1001/prebook'
href: '../api/offers/1001/prebook'
}
}
}
Expand All @@ -38,11 +38,11 @@ function offers (req, res) {
qualityOfService: '2nd',
_links: {
'self': {
href: 'offers/1002'
href: '../api/offers/1002'
},
'prebook': {
title: 'Book offer',
href: 'api/offers/1002/prebook'
href: '../api/offers/1002/prebook'
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/prebookings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ function prebook (req, res) {
description: 'Trip from Bern to Thun at 14.06.2017 20:04 for 16.60 CHF',
_links: {
'self': {
href: 'prebookings/2001'
href: '../api/prebookings/2001'
},
'confirm': {
title: 'Confirm prebooking',
href: 'api/prebookings/2001/confirm'
href: '../api/prebookings/2001/confirm'
}
}
}]
Expand Down
7 changes: 3 additions & 4 deletions api/controllers/prices.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ function prices (req, res) {
href: req.originalUrl
}

var prices = {
normalPrices: [830, 1660, 1460, 2920],
superSaverPrices: [420, 840, 740, 1460],
var prices = [{
price: 830,
_links: {
self
}
}
}]

res.json(prices)
}
Expand Down
6 changes: 3 additions & 3 deletions api/controllers/trips.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function trips (req, res) {

// TODO: Refactor into helper class
function constructSelfUrl (trip) {
let url = 'api/trips?'
let url = '../api/trips?'
url += 'originId=' + encodeURI(trip.segments[0].origin.id)
url += '&destinationId=' + encodeURI(trip.segments[0].destination.id)
url += '&date=' + encodeURI(trip.segments[0].origin.date)
Expand All @@ -110,7 +110,7 @@ function constructSelfUrl (trip) {
}

function constructPricesUrl (trip) {
let url = 'api/prices?'
let url = '../api/prices?'
url += 'originId=' + encodeURI(trip.segments[0].origin.id)
url += '&destinationId=' + encodeURI(trip.segments[0].destination.id)
url += '&date=' + encodeURI(trip.segments[0].origin.date)
Expand All @@ -119,7 +119,7 @@ function constructPricesUrl (trip) {
}

function constructOffersUrl (trip) {
let url = 'api/offers?'
let url = '../api/offers?'
url += 'originId=' + encodeURI(trip.segments[0].origin.id)
url += '&destinationId=' + encodeURI(trip.segments[0].destination.id)
url += '&date=' + encodeURI(trip.segments[0].origin.date)
Expand Down
53 changes: 41 additions & 12 deletions api/proxy/reverse.proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,46 @@
const request = require('request')
const REDIRECT_API = '/redirect_api/'
const createReverseProxy = (app, environmentConfiguration) => {

const proxyAPIRequest = (clientRequest, clientResponse) => {
const proxyAPIRequest = (env, clientRequest, clientResponse) => {
let headers = clientRequest.headers
let url = clientRequest.url.replace(REDIRECT_API, `${environmentConfiguration.backendReise}/api/`)
let url = clientRequest.url.replace(REDIRECT_API, environmentConfiguration['backend_' + env] + '/api/')
//TODO: Use Certificate solution instead of rejectUnauthorized: false
request(url, {headers, rejectUnauthorized: false}).pipe(clientResponse)
}

app.get('/redirect_api/*', function(clientRequest, clientResponse){
proxyAPIRequest(clientRequest, clientResponse)
})
request(url, {headers, rejectUnauthorized: false}, function (err, res, body) {
var manipulatedBody = body.toString();
for (var e in environmentConfiguration) {
if(e.startsWith("backend")) {
var regExp = new RegExp(environmentConfiguration[e] + "/api/", "g");
manipulatedBody = manipulatedBody.replace(regExp, "http://localhost:8080/redirect_api/");
}
}
clientResponse.send(manipulatedBody);
});
};

app.get(REDIRECT_API + 'locations*', function (clientRequest, clientResponse) {
proxyAPIRequest('locations', clientRequest, clientResponse)
});

app.get(REDIRECT_API + 'prices*', function (clientRequest, clientResponse) {
proxyAPIRequest('prices', clientRequest, clientResponse)
});

app.get(REDIRECT_API + 'trips*', function (clientRequest, clientResponse) {
proxyAPIRequest('trips', clientRequest, clientResponse)
});

app.get(REDIRECT_API + 'offers*', function (clientRequest, clientResponse) {
proxyAPIRequest('offers', clientRequest, clientResponse)
});

app.get(REDIRECT_API + 'prebookings*', function (clientRequest, clientResponse) {
proxyAPIRequest('prebookings', clientRequest, clientResponse)
});

app.get(REDIRECT_API + 'bookings*', function (clientRequest, clientResponse) {
proxyAPIRequest('bookings', clientRequest, clientResponse)
});

app.get('/basicAuth/login', function (clientRequest, clientResponse) {
let headers = clientRequest.headers
Expand All @@ -24,13 +53,13 @@ const createReverseProxy = (app, environmentConfiguration) => {
request(basicAuthURL, {headers, rejectUnauthorized: false}, function (request, response) {
if (response.statusCode === 200) {
clientResponse.send(response.headers.authorization)
}
else {
} else {
clientResponse.status(401).send({
message: 'Wrong username or password'
});
}
})
})
}
module.exports = createReverseProxy
};

module.exports = createReverseProxy;
Loading

0 comments on commit 61796ed

Please sign in to comment.