Skip to content

Commit

Permalink
Merge branch 'release/v0.0.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
schlpbch committed May 21, 2017
2 parents 39fb1ee + 859c3fb commit 5c33e8b
Show file tree
Hide file tree
Showing 39 changed files with 525 additions and 205 deletions.
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
FROM node:7-onbuild

ARG VCS_URL
ARG VCS_REF
ARG BUILD_DATE

LABEL org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="e.g. https://github.com/schlpbch/bookingAPI"

LABEL org.label-schema.vendor="SBB" \
org.label-schema.url="https://www.sbb.ch" \
org.label-schema.name="bookingAPI" \
org.label-schema.description="A simple API to book öV tickets in Switzerland." \
org.label-schema.vcs-url=$VCS_URL \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.build-date=$BUILD_DATE

CMD npm run prod
EXPOSE 8080
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Once the API is right, the API will be implemented of SBB's distribution system

More to come...

Here you can find a initial functional [road map](docs/roadmap.md).

## Installing
The easiest way is to pull the docker image:

Expand Down Expand Up @@ -42,19 +44,18 @@ The web app and the API are then running at http://localhost/

Using [docker-compose](https://docs.docker.com/compose/) a software defined
firewall (see [NGINX](https://www.nginx.com/))
is added in front of the mocked server and is linked to the mock server
server using a software defined network. This allows us to test
authentication methods using JSON Web Tokens (JWT) later.
is added in front of the mocked server and is linked to the mock server using a software defined network. This allows us to test
authentication methods using JSON Web Tokens ([JWT](https://jwt.io)) later.

See [docker-compose.yml](docker-compose.yml) for details.

To start simply us
To start simply use

```bash
docker-compose up
```

The server uses self signed certificates, must be replaced
The server uses self signed certificates, they must be replaced
with real ones for production!

## Live App and Documentation
Expand Down
42 changes: 26 additions & 16 deletions api/proxy/reverse.proxy.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
/**
* Created by kevinkreuzer on 05.05.17.
*/
'use strict'
const request = require('request')
const REDIRECT_API = '/redirect_api/'
const createReverseProxy = (app, environmentConfiguration) => {

const createReverseProxy = (app, backendReise) => {
const proxyRequest = (uri, req, res) => {
request(`${backendReise}/api/${uri}${req.params[0]}${req._parsedUrl.search ? req._parsedUrl.search : ''}`).pipe(res)
const proxyAPIRequest = (clientRequest, clientResponse) => {
let headers = clientRequest.headers
let url = clientRequest.url.replace(REDIRECT_API, `${environmentConfiguration.backendReise}/api/`)
//TODO: Use Certificate solution instead of rejectUnauthorized: false
request(url, {headers, rejectUnauthorized: false}).pipe(clientResponse)
}
app.get('/redirect_api/locations*', function (req, res) {
proxyRequest('locations', req, res)
})
app.get('/redirect_api/trips*', function (req, res) {
proxyRequest('trips', req, res)
})
app.get('/redirect_api/offers*', function (req, res) {
proxyRequest('offers', req, res)
})
app.get('/redirect_api/prebookings*', function (req, res) {
proxyRequest('prebookings', req, res)

app.get('/redirect_api/*', function(clientRequest, clientResponse){
proxyAPIRequest(clientRequest, clientResponse)
})
app.get('/redirect_api/bookings*', function (req, res) {
proxyRequest('bookings', req, res)

app.get('/basicAuth/login', function (clientRequest, clientResponse) {
let headers = clientRequest.headers
let basicAuthURL = environmentConfiguration.basicAuth_url
//TODO: Use Certificate solution instead of rejectUnauthorized: false
request(basicAuthURL, {headers, rejectUnauthorized: false}, function (request, response) {
if (response.statusCode === 200) {
clientResponse.send(response.headers.authorization)
}
else {
clientResponse.status(401).send({
message: 'Wrong username or password'
});
}
})
})
}
module.exports = createReverseProxy
2 changes: 1 addition & 1 deletion api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ swagger: '2.0'

## API Information
info:
version: '0.0.10'
version: '0.0.11'
title: "Simple öV booking API"
description: "A simple API to book öV tickets in Switzerland."
contact:
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SwaggerExpress.create(config, function (err, swaggerExpress) {
swaggerExpress.register(app)
app.use(morgan(environmentConfiguration.morganFormat))
app.use(express.static(path.join(__dirname, '/public')))
createReverseProxy(app, environmentConfiguration.backendReise)
createReverseProxy(app, environmentConfiguration)
app.listen(environmentConfiguration.appPort)

if (swaggerExpress.runner.swagger.paths['/offers']) {
Expand Down
1 change: 1 addition & 0 deletions config/environments/development.environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module.exports = {
backendReise: 'http://localhost:8080',
backendOrch: 'http://localhost:8080',
basicAuth_url: 'https://zvs-api-test-ws.sbb.ch/login-jwt',
appPort: 8080,
morganFormat: 'dev'
}
2 changes: 1 addition & 1 deletion config/environments/environment.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ const loadEnvironmentConfig = () => {

module.exports = {
loadEnvironmentConfig
}
}
1 change: 1 addition & 0 deletions config/environments/production.environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module.exports = {
backendReise: process.env.BACKEND_REISE || 'http://localhost:8080',
backendOrch: process.env.BACKEND_ORCH || 'http://localhost:8080',
basicAuth_url: 'https://zvs-api-test-ws.sbb.ch/login-jwt',
appPort: process.env.PORT || 8080,
morganFormat: 'common'
}
1 change: 1 addition & 0 deletions config/nginx/.htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
api-pitch:$apr1$EMjhOYRi$fHpoKIivnsBNUDiatsHcS/
48 changes: 29 additions & 19 deletions config/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
upstream nodejs_backend {
server mock_server:8080;
server mock_server:8080;
}

server {
listen 80 default_server;
listen 443 default_server ssl;
listen 80 default_server;
listen 443 default_server ssl;

ssl_certificate /etc/nginx/ssl/public.pem;
ssl_certificate_key /etc/nginx/ssl/private.pem;
ssl_certificate /etc/nginx/ssl/public.pem;
ssl_certificate_key /etc/nginx/ssl/private.pem;

client_max_body_size 8k;
charset UTF-8;
client_max_body_size 8k;
charset UTF-8;

server_name localhost;
location / {
expires 15m;
add_header Pragma public;
add_header Cache-Control "public";
proxy_pass http://nodejs_backend/;
}
server_name localhost;
location / {
expires 15m;
add_header Pragma public;
add_header Cache-Control "public";
proxy_pass http://nodejs_backend/;
}

gzip on;
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
server_name localhost;
location /app/api-pitch/ {
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
expires 1d;
add_header Pragma public;
add_header Cache-Control "public";
proxy_pass http://nodejs_backend/app/api-pitch/;
}

gzip on;
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
}
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ services:
- "443:443"
volumes:
- ./config/nginx/nginx.conf:/etc/nginx/conf.d/default.conf/
- ./config/nginx/.htpasswd:/etc/nginx/.htpasswd
- ./config/nginx/ssl/:/etc/nginx/ssl/
depends_on:
- mock_server
networks:
- front

mock_server:
image: schlpbch/bookingapi:latest
build: .
image: schlpbch/bookingapi:develop
ports:
- "8080:8080"
networks:
Expand Down
66 changes: 66 additions & 0 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Roadmap 2017 R75-R84
ASC, TAK, DIW (18.05.2017)

### R75 Deep Link Relase
- journey planning
- get locations
- get trips
- deep linking
- link to webshop B2C
- link to mobile B2C

### R78 First Light Release
- commercial registration (contract, bill put)
- accounting for trade partners
- accountung for KTU
- picking of booking

- master data for locations (HD)

- distribution per tickets (HD)
- via eMail
- via SMS

- fullfilement
- bar code
- screen ticket
- pass-book (HD)

- route based distribution (origin, destination, {via})
- assortment
- City Tickets
- Verbund Tickets

### R81 Version 1.0 Release
- after sales:
- state of booking e.g., cancelled, printed,...
- refund of a booking
- more than 1 person (child, adult, senior)
- more than 0 vias
- for trips
- for offers
- seat reservation
- fulfilement:
- ticket Layouting for KTUs (print attributes -> ticket)

### R84 Best Prices Finder Release
- product based distribution
- assortment
- STS passes
- Tageskarte DV (prenom, name, birthday -> ticket)
- RIT
- tailor made ticket

- best prices per time period

### R8x Future Releases (not scheduled yet)
- location based trip search
- assortment
- Tageskarte Verbund (prenom, name, birthday -> ticket)
- product information (fares & conditions)
- direct booking
- after sales: exchange
- STS Sortiment
- STS Pass
- STS Flex Pass
- More than 1 person (family fares)
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bookingAPI",
"version": "0.0.10",
"version": "0.0.11",
"private": true,
"description": "A simple API to book öV tickets in Switzerland.",
"keywords": [
Expand All @@ -17,6 +17,7 @@
"angular": "^1.6.0",
"angular-animate": "^1.6.0",
"angular-aria": "^1.6.0",
"angular-jwt": "^0.1.9",
"angular-material": "^1.1.4",
"angular-messages": "^1.6.0",
"angular-route": "^1.6.0",
Expand Down Expand Up @@ -49,7 +50,7 @@
},
"scripts": {
"serve": "concurrently \"npm run watchify\" \"npm run browsersync\"",
"browsersync": "browser-sync start --startPath='./public' --server --files './public/*.html, ./public/bundle.js'",
"browsersync": "browser-sync start --startPath='./public/app' --server --files './public/*.html, ./public/bundle.js'",
"watchify": "watchify -t browserify-css public/app/components/app.js -o public/app/bundle.js -d -t [ babelify --presets [ es2015 react ] ]",
"predev": "browserify -t browserify-css public/app/components/app.js -o public/app/bundle.js -d -t [ babelify --presets [ es2015 react ] ]",
"dev": "node app.js",
Expand Down
13 changes: 9 additions & 4 deletions public/app/components/app.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
* Created by kevinkreuzer on 15.03.17.
*/
export default class AppController {
constructor (tabService, bookingStore) {
this.tabService = tabService
this.bookingStore = bookingStore
}
constructor(tabService, bookingStore, authService) {
this.tabService = tabService
this.bookingStore = bookingStore
this.authService = authService
}

isAuthenticated() {
return this.authService.hasValidToken()
}
}
34 changes: 18 additions & 16 deletions public/app/components/app.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<md-content layout="column">
<api-toolbar></api-toolbar>
</md-content>

<div flex layout="row">
<api-sidenav></api-sidenav>
<md-content layout-padding flex>
<md-tabs md-dynamic-height md-border-bottom md-selected="$ctrl.tabService.selectedTab">
<api-travel-wish></api-travel-wish>
<api-connections></api-connections>
<api-offers></api-offers>
<api-prebooking></api-prebooking>
<api-booking></api-booking>
</md-tabs>
<div>
<md-content layout="column">
<api-toolbar></api-toolbar>
</md-content>
<api-error-log></api-error-log>
</div>

<div flex layout="row">
<api-sidenav></api-sidenav>
<md-content layout-padding flex>
<md-tabs md-dynamic-height md-border-bottom md-selected="$ctrl.tabService.selectedTab">
<api-travel-wish></api-travel-wish>
<api-connections></api-connections>
<api-offers></api-offers>
<api-prebooking></api-prebooking>
<api-booking></api-booking>
</md-tabs>
</md-content>
<api-error-log></api-error-log>
</div>
</div>
Loading

0 comments on commit 5c33e8b

Please sign in to comment.