-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
89 lines (72 loc) · 2.7 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var express=require('express');
var exphbs=require('express-handlebars');
var hbs_sections=require('express-handlebars-sections');
const Handlebars = require('handlebars');
const HandlebarsIntl = require('handlebars-intl');
var guestRole = require('./middlewares/guestRole.mdw');
var paginate = require('handlebars-paginate');
var app=express();
app.use(express.static('public'));
Handlebars.registerHelper('customNumberFormat', function(value){
var context = {
value: value
};
var intlData = {
locales: ['en-US'],
};
// use the formatNumber helper from handlebars-intl
var template = Handlebars.compile('{{formatNumber value}} is the final result!');
var compiled = template(context, {
data: {intl: intlData}
});
return compiled
});
app.engine('hbs',exphbs({
defaultLayout:'main_public.hbs',
layoutsDir:'views/layouts',
helpers:{
section:hbs_sections()
}
}));
app.set('view engine','hbs');
app.use('/',require('./routes/homepage.route'));
app.use('/category',require('./routes/category.route'));
app.use('/contact',require('./routes/contact.route'));
app.use('/forgot',require('./routes/forgot.route'));
app.use('/login',require('./routes/login.route'));
app.use('/register',require('./routes/register.route'));
app.use('/page',require('./routes/page.route'));
app.use('/search',require('./routes/search.route'));
app.use('/starter',require('./routes/starter.route'));
app.use('/article',require('./routes/article.route'));
app.use('/auth/profile',require('./routes/profile.route'));
app.use('/auth/writer',require('./routes/writer/dashboard.route'));
app.use('/auth/editor',require('./routes/editor/dashboard.route'));
app.use('/auth/admin',require('./routes/admin/dashboard.route'));
app.use('/authentication', require('./routes/authentication.route'));
app.use('/auth/info', require('./routes/info.route'));
app.use('/auth/register/subscriber', require('./routes/register_subscriber.route'))
app.use('/auth/subscriber', require('./routes/subscriber.route'));
app.use((req,res,next)=>{
res.render('404',{layout:false});
})
// app.use((error,req,res,next)=>{
// res.render('500',{layout:false});
// })
Handlebars.registerHelper('grouped_each', function(every, context, options) {
var out = "", subcontext = [], i;
if (context && context.length > 0) {
for (i = 0; i < context.length; i++) {
if (i > 0 && i % every === 0) {
out += options.fn(subcontext);
subcontext = [];
}
subcontext.push(context[i]);
}
out += options.fn(subcontext);
}
return out;
});
app.listen(3000,()=>{
console.log('server is running at http://localhost:3000');
})