Skip to content

Commit

Permalink
DEV: Set up template engine (#24)
Browse files Browse the repository at this point in the history
closes #24
  • Loading branch information
dwhieb committed May 5, 2024
1 parent 85e3fbe commit 80e7c1a
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/handlebars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ExpressHandlebars } from 'express-handlebars'
import path from 'node:path'

const hbs = new ExpressHandlebars({
extname: `hbs`,
layoutsDir: path.resolve(import.meta.dirname, `../layouts`),
})

export default hbs
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import 'dotenv/config'
import * as handlers from './app/handlers.js'
import express from 'express'
import handleUncaughtException from './app/errors.js'
import hbs from './app/handlebars.js'
import helmet from 'helmet'
import logger from './middleware/logger.js'
import path from 'node:path'
import serveStatic from './middleware/static.js'
import vary from './middleware/vary.js'

Expand All @@ -17,7 +19,10 @@ const app = express()

// Settings
app.enable(`trust proxy`)
app.engine(`hbs`, hbs.engine)
app.set(`env`, process.env.NODE_ENV)
app.set(`view engine`, `hbs`)
app.set(`views`, path.resolve(import.meta.dirname, `./pages`))

// Middleware
app.use(helmet())
Expand Down
2 changes: 1 addition & 1 deletion middleware/static.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'

const oneWeek = 604800
const staticFilesPath = path.join(import.meta.dirname, `../assets`)
Expand Down
Loading

0 comments on commit 80e7c1a

Please sign in to comment.