Switch to ejs templates

This commit is contained in:
Linus Miller 2018-02-02 22:29:26 +01:00
parent 75ce309838
commit eeea7f792c
4 changed files with 36 additions and 3 deletions

View File

@ -18,11 +18,12 @@
"dependencies": {
"body-parser": "^1.18.2",
"chalk": "^2.3.0",
"ejs": "^2.5.7",
"express": "^4.16.2",
"handlebar": "^1.0.0",
"knex": "^0.14.2",
"morgan": "^1.9.0",
"node-fetch": "^1.7.3"
"node-fetch": "^1.7.3",
"xml2js": "^0.4.19"
},
"devDependencies": {
"eslint": "^4.16.0",

View File

@ -2,11 +2,22 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
// modules > native
const path = require('path')
// modules > 3rd party
const express = require('express')
const bodyParser = require('body-parser')
const chalk = require('chalk')
// initialize an express instance
const server = express()
// set template engine
server.set('view engine', 'ejs')
server.set('views', path.join(__dirname, 'templates'))
// set up console logs in dev mode
if (process.env.NODE_ENV !== 'production') {
const morgan = require('morgan')
@ -18,11 +29,28 @@ server.use(bodyParser.urlencoded({ extended: true }))
server.use('/', (req, res, next) => {
console.log('hello')
res.send('<h1>Hello</h1>')
res.render('index')
})
server.use('/search', (req, res, next) => {
res.render('search')
})
server.use('/search-result', (req, res, next) => {
res.render('result')
})
// server.use('/', (req, res, next) => {
// console.log('hello')
// res.send('<h1>Hello</h1>')
// })
const port = process.env.port || 1337
server.listen(port, () => {
console.info(`[${chalk.cyan('INIT')}] HTTP Server listening on port ${chalk.magenta(port)} (${chalk.yellow(server.get('env'))})`)
})
const goodreads = require('./api/goodreads')
goodreads.search().then((result) => console.dir(result, { colors: true, depth: 5 }))

View File

@ -0,0 +1 @@
<h1>Penis</h1>

View File

@ -0,0 +1,3 @@
<% include header %>
<h1>An awesome template</h1>
{{>header }}