-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
74 lines (65 loc) · 2.06 KB
/
app.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const path = require('path')
const express = require('express')
const hbs = require('express-handlebars')
const router = require('./routes/index.js')
const bodyParser = require('body-parser')
const convertToIcons = require('./helpers/convertToIcons.js')
const mongoose = require('mongoose')
mongoose.connect(process.env.MONGODB_URI)
const favicon = require('serve-favicon')
require('env2')('./config.env')
const app = express()
const db = mongoose.connection
app.set('port', process.env.PORT || 4444)
// import the languages object and set the default language and text dir for arabic
const languages = require('./text.js')
const language = 'arabic'
const lang = 'ar'
const text = languages[language]
const dir = 'rtl'
app.locals.dir = dir
app.locals.text = text
app.locals.lang = lang
const pubPath = path.join(__dirname, './', 'public')
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.use(favicon(path.join(__dirname, './public', 'favicon.ico')))
app.use(express.static(pubPath))
app.engine('hbs', hbs({
defaultLayout: 'main',
defaultDir: path.join(__dirname, './', 'views/layouts'),
partialsDir: path.join(__dirname, './', 'views/partials'),
extname: 'hbs',
helpers: {
serviceInfoLink: (id) => {
return `href="/serviceinfo?id=${id}"`
},
mapSrcLink: () => {
return `https://maps.googleapis.com/maps/api/js?key=${process.env.GOOGLE_API}&callback=_myMap`
},
convertToIcons: convertToIcons,
chooseBack: (dir) => {
if (dir === 'ltr') {
return 'fa fa-arrow-left fl'
} else {
return 'fa fa-arrow-right fr'
}
},
bgImg: (name) => {
if ((typeof name) === 'object') {
name = name[0]
}
name = name.toLowerCase().replace(/\s/g, '-')
return `bg-${name}`
}
}
}))
app.set('view engine', 'hbs')
app.set('views', path.join(__dirname, './', 'views'))
app.use(router)
db.on('error', console.error.bind(console, 'connection error:'))
db.once('open', () => {
app.listen(app.get('port'), () => {
console.log('Server running on port:', app.get('port'))
})
})