-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
110 lines (90 loc) · 2.96 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const path = require('path');
const i18n = require('i18n');
const exphbs = require('express-handlebars');
const express = require('express');
var hbs = require('hbs');
var fs = require('fs');
var bodyParser = require('body-parser');
const app = express();
const jwt = require('jsonwebtoken');
var passport = require('passport');
require('./config/passport')(passport); // pass passport for configuration
var cookieParser = require('cookie-parser');
var session = require('express-session');
const checkAuth = require('check-auth');
var morgan = require('morgan');
var flash = require('connect-flash');
const routes = require('./routes');
const helmet = require('helmet');
const port = process.env.PORT || 3001;
app.engine('.hbs', exphbs({
extname: '.hbs',
layoutsDir: path.join(__dirname, 'views/layouts'),
partialsDir: [
__dirname + '/views/layouts/partials',
]
}))
i18n.configure({
locales:['en', 'he'],
directory: __dirname + '/locales',
defaultLocale: 'en',
cookie: 'i18n'
});
app.use(express.json());
app.use(morgan('combined'));
app.use(helmet());
app.use(bodyParser.json());
app.use(cookieParser()); // read cookies (needed for auth)
app.use(cookieParser("i18n_demo")); //demo
app.use(session({
secret: "i18n_demo",
resave: true,
saveUninitialized: true,
cookie: { maxAge: 365 * 24 * 60 * 60 * 1000 }
}));
app.use(i18n.init);
var hbs = require('hbs');
hbs.registerHelper('__', function () {
return i18n.__.apply(this, arguments);
});
hbs.registerHelper('__n', function () {
return i18n.__n.apply(this, arguments);
});
// required for passport
app.use(session({ secret: 'backstagekey', resave: false, saveUninitialized: false, cookie: { maxAge: 365 * 24 * 60 * 60 * 1000 } })); // session secret
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, '/views/images')));
app.use(flash()); // use connect-flash for flash messages stored in session
app.set('view engine', '.hbs');
app.set('views', path.join(__dirname, 'views'));
var partialsDir = __dirname + '/views/layouts/partials';
var filenames = fs.readdirSync(partialsDir);
filenames.forEach(function (filename) {
var matches = /^([^.]+).hbs$/.exec(filename);
if (!matches) {
return;
}
var name = matches[1];
var template = fs.readFileSync(partialsDir + '/' + filename, 'utf8');
hbs.registerPartial(name, template);
});
app.use('/', routes);
app.get('/he', function (req, res) {
res.cookie('i18n', 'he');
res.redirect('/')
});
app.get('/en', function (req, res) {
res.cookie('i18n', 'en');
res.redirect('/')
});
app.listen(port, (err) => {
if (err) {
return console.log('Something bad happened', err)
}
console.log(`server is listening on ${port}`)
})
// owl-carousel
app.use('/modules', express.static(path.join(__dirname, 'node_modules')))
app.use('/css', express.static(path.join(__dirname, 'views/layouts/css')))