-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (34 loc) · 1.35 KB
/
server.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
'use strict';
const http = require('http');
const path = require('path');
// configuration
const config = require('./config/environment.json');
const isRelease = process.argv.length === 3 ? process.argv[2] === 'release' : undefined;
config.publicDirectoryPath = path.join(__dirname, 'public');
config.server.port = config.server.port || 3000;
config.isRelease = isRelease === undefined ? config.isRelease : isRelease;
// catberry application
const catberry = require('catberry');
const cat = catberry.create(config); // the Catberry application object
cat.events.on('ready', () => {
const logger = cat.locator.resolve('logger');
logger.info(`Ready to handle incoming requests on port ${config.server.port}`);
});
// register Catberry plugins needed on the server
const templateEngine = require('catberry-pug');
templateEngine.register(cat.locator);
const loggerPlugin = require('catberry-logger');
loggerPlugin.register(cat.locator);
const uhrPlugin = require('catberry-uhr');
uhrPlugin.register(cat.locator);
// web server
const express = require('express');
const app = express();
const serveStatic = require('serve-static');
app.use(serveStatic(config.publicDirectoryPath));
app.use(cat.getMiddleware()); // Catberry app as a middleware
const errorhandler = require('errorhandler');
app.use(errorhandler());
http
.createServer(app)
.listen(config.server.port);