This repository was archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (42 loc) · 1.22 KB
/
Copy pathapp.js
File metadata and controls
51 lines (42 loc) · 1.22 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Boot
const boot = require('./app/boot/boot')
// Express
const express = require('express')
const app = express()
app.use('/', express.static('public'))
app.use('/third_party', express.static('third_party'))
// BodyParser
app.use(express.urlencoded({ extended: true }))
// CookieParser
const cookieParser = require('cookie-parser')
app.use(cookieParser())
// Handlebars
const exphbs = require('express-handlebars')
app.set('views', [`views`])
app.set('view engine', 'hbs')
app.engine('hbs', exphbs({
defaultLayout: 'main',
extname: '.hbs',
layoutsDir: `views/layouts`,
helpers: require('./app/helpers/handlebars'),
}))
// Routes
require('./app/routes/routes')(app)
// Open in browser
const open = require('open')
const chalk = require('chalk')
const webserverPort = 36554
const webserver = () => {
app.listen(webserverPort, (err) => {
if (err) {
console.log(`\x1b[1m\x1b[2m[WEBSERVER] - \x1b[0m\x1b[1m\x1b[31m\x1b[5mFAILED\x1b[0m\x1b[31m: Unable to bind to port 36554. Could there possibly be another instance alive?\x1b[0m`)
process.exit(1)
}
})
}
// Load SQLize models
boot().then(() => {
require('./app/models').sequelize.sync().then(() => {
webserver()
})
})