Skip to content

Commit 9759a29

Browse files
committed
Fix Server Static Routing
1 parent 491bc09 commit 9759a29

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

js/stores/stationStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export class stationStore extends Events {
269269

270270
// we need to pass an extra param for train trips
271271
var requestData
272-
if (tripData[0].route_type === '2') {
272+
if (tripData[0].route_type === 2) {
273273
requestData = JSON.stringify({
274274
trips: queryString,
275275
train: true

server/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var line = require('./line')
66
var email = require('./email')
77
var vehicle = require('./vehicle')
88
var search = require('./search')
9-
var sitemap = require('./sitemap')
109

1110
console.log('using AT API Key: ' + process.env.atApiKey)
1211
console.log('using SendGrid API Key: '+ process.env.SENDGRID_API_KEY)
@@ -15,6 +14,7 @@ console.log('using SendGrid API Key: '+ process.env.SENDGRID_API_KEY)
1514
cache.check()
1615
setInterval(cache.check, 1800000)
1716

17+
// TODO: 301 redirects
1818
router.get('/station', station.stopInfo)
1919
router.get('/station/search', search.getStopsLatLng)
2020
router.get('/station/:station', station.stopInfo)

server/realtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ var realtime = {
102102
res.send(rt)
103103
}
104104
},
105-
getTripsAuckland: function(trips, train = false) {
105+
getTripsAuckland: function(trips, train = false) {
106106
var realtimeInfo = {}
107107
trips.forEach(function(trip) {
108108
realtimeInfo[trip] = {}

server/staticrender.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ const staticrender = {
3131
canonical = 'https://transit.dymajo.com'
3232
success()
3333
} else if (path[1] === 's') {
34-
if (path.length === 2) {
35-
return notFound()
36-
} else if (path.length === 3) {
37-
station._stopInfo(path[2], 'nz-akl').then(function(data) {
34+
if (path.length === 3) {
35+
path.splice(2, 0, 'nz-akl')
36+
return res.redirect(301, path.join('/'))
37+
// return res.redirect(301, ca)
38+
} else if (path.length === 4) {
39+
station._stopInfo(path[3], 'nz-akl').then(function(data) {
3840
title = data.stop_name + defaultName
3941
description = 'Realtime departures and timetable for '
4042
if (data.stop_name.toLowerCase().match('train station')||
@@ -47,12 +49,12 @@ const staticrender = {
4749

4850
success()
4951
}).catch(notFound)
50-
} else if (path.length === 5) {
51-
if (path[3] === 'timetable') {
52-
title = path[4].split('-')[0] + ' Timetable' + defaultName
52+
} else if (path.length === 6) {
53+
if (path[4] === 'timetable') {
54+
title = path[5].split('-')[0] + ' Timetable' + defaultName
5355
description = 'View timetable in DYMAJO Transit.'
5456
success()
55-
} else if (path[3] === 'realtime') {
57+
} else if (path[4] === 'realtime') {
5658
title = 'Realtime Trip Info' + defaultName
5759
description = 'View live vehicle location in DYMAJO Transit.'
5860
success()
@@ -64,12 +66,15 @@ const staticrender = {
6466
}
6567
} else if (path[1] === 'l') {
6668
if (path.length === 2) {
69+
path.splice(2, 0, 'nz-akl')
70+
return res.redirect(301, path.join('/'))
71+
} else if (path.length === 3) {
6772
title = 'Lines' + defaultName
6873
description = 'View all Auckland Bus, Train, and Ferry Services.'
6974
success()
70-
} else if (path.length === 3) {
71-
path[2] = path[2].trim()
72-
line._getLine(path[2], function(err, data) {
75+
} else if (path.length === 4) {
76+
path[3] = path[3].trim()
77+
line._getLine(path[3], function(err, data) {
7378
if (data.length === 0) {
7479
return notFound()
7580
} else {

server/station.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ var station = {
8181
today.setUTCMonth(time.month())
8282
today.setUTCDate(time.date())
8383

84+
// midnight fix
85+
if (time.hour() < 5) {
86+
today.subtract(1, 'day')
87+
}
88+
8489
const realtimeTrips = []
8590
connection.get().request()
8691
.input('prefix', sql.VarChar(50), prefix)

0 commit comments

Comments
 (0)