-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
36 lines (29 loc) · 894 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const express = require('express')
const hbs = require('express-handlebars')
const fs = require('fs')
const router = require('./routes')
const path = require('path')
const utils = require('./utils')
const db = require('./db/index')
const server = express()
// SERVER CONFIGURATION
server.use(express.static(path.join(__dirname, 'public')))
server.use(express.urlencoded({ extended: true }))
// HANDLEBARS CONFIGURATION
server.engine('hbs', hbs.engine({ extname: 'hbs' }))
server.set('view engine', 'hbs')
//Routes
server.use('/', router)
server.get('/', (req, res) => {
db.getPalettes()
.then((palettes) => {
let parsedColors = utils.parseColors(palettes)
let heroPalette = parsedColors[utils.randomNum(parsedColors)]
res.render('home', heroPalette)
})
.catch((err) => {
console.log(err)
res.send('No good my friend.' + err.message)
})
})
module.exports = server