Skip to content

Commit 07837af

Browse files
authored
Add route to retrieve GTFS feed info from microservice (#271)
1 parent 4bed1e1 commit 07837af

8 files changed

Lines changed: 51 additions & 14 deletions

File tree

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
- /usr/src/app/node_modules
1414

1515
ghopper:
16-
image: cornellappdev/transit-ghopper:v1.0.2
16+
image: cornellappdev/transit-ghopper:v1.0.7
1717
ports:
1818
- "8988:8988"
1919

@@ -28,7 +28,7 @@ services:
2828
- "8987:8987"
2929

3030
live-tracking:
31-
image: cornellappdev/transit-python:v1.0.2
31+
image: cornellappdev/transit-python:v1.0.7
3232
env_file: python.envrc
3333
ports:
3434
- "5000:5000"

envrc.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ NODE_ENV=production
55
PLACES_KEY=PLACES_KEY
66
PORT=3000
77
PYTHON_APP=live-tracking
8+
PYTHON_PORT=5000
89
RELEASE_URL=http://localhost:3001/
910
TOKEN=TOKEN

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/API.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class API extends ApplicationAPI {
2121
Routers.AppleSearchRouter,
2222
Routers.DelayRouter,
2323
Routers.DelaysRouter,
24+
Routers.GTFSFeedInfoRouter,
2425
Routers.HelloWorldRouter,
2526
Routers.MultiRouteRouter,
2627
Routers.PlacesAutocompleteRouter,

src/routers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import AppleSearchRouter from './v1/AppleSearchRouter';
55
import DelayRouter from './v1/DelayRouter';
66
import DelaysRouter from './v2/DelaysRouter';
77
import DocsRouter from './DocsRouter';
8+
import GTFSFeedInfoRouter from './v1/GTFSFeedInfoRouter';
89
import HelloWorldRouter from './v1/HelloWorldRouter';
910
import MultiRouteRouter from './v1/MultiRouteRouter';
1011
import PlacesAutocompleteRouter from './v1/PlacesAutocompleteRouter';
@@ -23,6 +24,7 @@ export default {
2324
DelayRouter,
2425
DelaysRouter,
2526
DocsRouter,
27+
GTFSFeedInfoRouter,
2628
HelloWorldRouter,
2729
MultiRouteRouter,
2830
PlacesAutocompleteRouter,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @flow
2+
import GTFSUtils from '../../utils/GTFSUtils';
3+
import ApplicationRouter from '../../appdev/ApplicationRouter';
4+
5+
class GTFSFeedInfoRouter extends ApplicationRouter<Array<Object>> {
6+
constructor() {
7+
super(['GET']);
8+
}
9+
10+
getPath(): string {
11+
return '/GTFSFeedInfo/';
12+
}
13+
14+
// eslint-disable-next-line require-await
15+
async content(req): Promise<any> {
16+
return GTFSUtils.getFeedInfo();
17+
}
18+
}
19+
20+
export default new GTFSFeedInfoRouter().router;

src/utils/EnvUtils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
MAP_MATCHING,
66
NODE_ENV,
77
PYTHON_APP,
8+
PYTHON_PORT,
89
TOKEN,
910
} = process.env;
1011

@@ -14,5 +15,6 @@ export {
1415
MAP_MATCHING,
1516
NODE_ENV,
1617
PYTHON_APP,
18+
PYTHON_PORT,
1719
TOKEN,
1820
};

src/utils/GTFSUtils.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
// @flow
2-
import { PYTHON_APP } from './EnvUtils';
2+
import { PYTHON_APP, PYTHON_PORT } from './EnvUtils';
33
import RequestUtils from './RequestUtils';
44

55
async function fetchRoutes(): Object {
66
const options = {
77
method: 'GET',
8-
url: `http://${PYTHON_APP || 'localhost'}:5000/gtfs`,
8+
url: `http://${PYTHON_APP || 'localhost'}:${+PYTHON_PORT}/gtfs`,
99
headers: { 'Cache-Control': 'no-cache' },
1010
};
1111
const data = await RequestUtils.createRequest(options, 'Fetch routes request failed');
1212
return JSON.parse(data);
1313
}
1414

15+
async function getFeedInfo(): Object {
16+
const options = {
17+
method: 'GET',
18+
url: `http://${PYTHON_APP || 'localhost'}:${+PYTHON_PORT}/gtfs-feed-info`,
19+
headers: { 'Cache-Control': 'no-cache' },
20+
};
21+
const data = await RequestUtils.createRequest(options, 'Get GTFS feed info request failed');
22+
return JSON.parse(data);
23+
}
24+
1525
export default {
1626
fetchRoutes,
27+
getFeedInfo,
1728
};

0 commit comments

Comments
 (0)