Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
RestaurantReviews/index.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
58 lines (43 sloc)
1.31 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin / env node | |
//Routes File | |
'use strict' | |
/* MODULE IMPORTS */ | |
const Koa = require('koa') | |
const Router = require('koa-router') | |
const views = require('koa-views') | |
const staticDir = require('koa-static') | |
const bodyParser = require('koa-bodyparser') | |
const session = require('koa-session') | |
const Handlebars = require('handlebars') | |
const app = new Koa() | |
const router = new Router() | |
/* CONFIGURING THE MIDDLEWARE */ | |
app.keys = ['darkSecret'] | |
app.use(staticDir('public')) | |
app.use(bodyParser()) | |
app.use(session(app)) | |
app.use(views(`${__dirname}/views`, { extension: 'handlebars' }, { map: { handlebars: 'handlebars' } })) | |
const home = require('./routes/home.js') | |
const user = require('./routes/user.js') | |
const restaurant = require('./routes/restaurant.js') | |
const review = require('./routes/review.js') | |
const defaultPort = 8080 | |
const port = process.env.PORT || defaultPort | |
/*Session Data | |
ctx.session.authorised | |
ctx.session.user | |
ctx.session.usertype | |
*/ | |
app.use(home.routes()) | |
app.use(user.routes()) | |
app.use(restaurant.routes()) | |
app.use(review.routes()) | |
Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) { | |
if (arg1 === arg2) { | |
return options.fn(this) | |
} else { | |
return options.inverse(this) | |
} | |
}) | |
app.use(router.routes()) | |
module.exports = app.listen(port, async() => console.log(`listening on port ${port}`)) |