import express from 'express'
import session from 'express-session'
import path from 'path'
import favicon from 'serve-favicon'
import logger from 'morgan'
import cookieParser from 'cookie-parser'
import bodyParser from 'body-parser'
import mongoose from 'mongoose'
import passport from 'passport'
import flash from 'connect-flash'

/* Express setup */
let app = express()

// view engine setup
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
app.set('api version', '1.0')

app.use(favicon(path.join(__dirname, 'public/favicon.ico')))
app.use(logger('short'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
  extended: false
}))
app.use(cookieParser())
app.use(session({
  secret: 'pusheeeen',
  resave: false,
  saveUninitialized: false
}))
app.use(express.static(path.join(__dirname, 'public')))
app.use(flash())
app.use(passport.initialize())
app.use(passport.session())

// Initialize mongoose singleton
if (!process.env.MONGO_URL) {
  throw new Error('Missing MONGO_URL environment variable')
}
mongoose.connect(process.env.MONGO_URL)

/* Front end routes */
import index from './routes/index'
import docs from './routes/docs'
app.use('/', index)
app.use('/docs', docs)

/* User routes */
import user from 'user'
app.use('/user', user)

/* API routes */
import uoftCourseApi from 'uoft-course-api'
import uoftBuildingApi from 'uoft-building-api'
import uoftFoodApi from 'uoft-food-api'
app.use('/api/courses', uoftCourseApi)
app.use('/api/buildings', uoftBuildingApi)
app.use('/api/food', uoftFoodApi)


/* Error handlers */

// catch 404 and forward to error handler
app.use((req, res, next) => {
  let err = new Error('Not Found')
  err.status = 404
  next(err)
})

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use((err, req, res, next) => {
    res.status(err.status || 500)
    res.json({
      error: {
        code: err.status,
        message: err.message
      }
    })
  })
}

// production error handler
// no stacktraces leaked to user
app.use((err, req, res, next) => {
  res.status(err.status || 500)
  res.render('error', {
    message: err.message,
    error: {}
  })
})

export default app

@@ -1426,24 +1426,64 @@
 od-api'%0A
+let apiVersion = app.get('api version')%0A
 app.use(
 '/api/co
@@ -1478,22 +1478,36 @@
 use(
-'
+%60
 /api/
+$%7BapiVersion%7D/
 courses
-'
+%60
 , uo
@@ -1527,22 +1527,36 @@
 app.use(
-'
+%60
 /api/
+$%7BapiVersion%7D/
 building
@@ -1556,17 +1556,17 @@
 uildings
-'
+%60
 , uoftBu
@@ -1588,19 +1588,33 @@
 use(
-'
+%60
 /api/
+$%7BapiVersion%7D/
 food
-'
+%60
 , uo

Add version number to API routes with string interpolation