-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
80 lines (59 loc) · 1.91 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
import express from 'express';
import debug from 'debug';
import dotenv from 'dotenv';
import path from 'path';
// import subdomain from 'express-subdomain'
import vhost from 'vhost';
const expressApp = express();
dotenv.config();
debug.enable('app');
// Set the view engine to EJS
expressApp.set('view engine', 'ejs');
// Middlewares and session
// Initialize session middleware for blog subdomain
app.use(vhost('blog.localhost', session({
secret: 'blog secret',
resave: false,
saveUninitialized: true,
cookie: {
domain: 'blog.localhost'
}
})));
import blogRouter from './routes/blogRoutes.js'
app.use(vhost('blog.localhost', blogRouter))
// Initialize session middleware for admin subdomain
app.use(vhost('admin.localhost', session({
secret: 'admin secret',
resave: false,
saveUninitialized: true,
cookie: {
domain: 'admin.localhost'
}
})));
import adminRouter from './routes/adminRoutes.js'
app.use(vhost('admin.localhost', adminRouter))
// Initialize session middleware for main domain
app.use(session({
secret: 'main secret',
resave: false,
saveUninitialized: true,
cookie: {
domain: 'localhost'
}
}));
import homeRouter from './routes/homeRoutes.js';
app.use('/', homeRouter)
// expressApp.set('views', path.join(__dirname, 'views'));
// // import and apply routers
// import blogRouter from './routes/blogRoutes.js'
// expressApp.use(vhost('blog.localhost', blogRouter))
// import adminRouter from './routes/adminRoutes.js'
// expressApp.use(vhost('admin.localhost', adminRouter))
// import homeRouter from './routes/homeRoutes.js';
// expressApp.use('/', homeRouter)
async function startApplication() {
expressApp.listen(process.env.PORT || 8080, process.env.HOSTNAME || '0.0.0.0', () => {
debug('app')(`Server is running on http://${process.env.HOSTNAME || '0.0.0.0'}:${process.env.PORT || 8080}`);
});
}
startApplication();