1 | let { chalk: { ok } } = require('../namespace/console');
|
2 | const args = require('optimist').argv;
|
3 | const debug = require('debug')('glad');
|
4 |
|
5 | module.exports = class Server {
|
6 |
|
7 | constructor (project) {
|
8 | debug('Server:constructor');
|
9 | this.express = require('express');
|
10 | this.app = this.express();
|
11 | this.server = require('http').createServer(this.app);
|
12 | this.websockets = require('socket.io')(this.server);
|
13 | this.project = project;
|
14 | }
|
15 |
|
16 | listen () {
|
17 | debug('Server:listen');
|
18 | let { port, host, sock, backlog } = this.project.config;
|
19 |
|
20 | if (args.port) port = Number(args.port);
|
21 | if (args.host) host = args.host;
|
22 | if (args.sock) sock = args.sock;
|
23 | if (args.backlog) backlog = Number(args.backlog);
|
24 |
|
25 | if (process.env['CONSOLE_MODE']) {
|
26 | ok('Running in Console Mode');
|
27 | } else {
|
28 | this.server.listen(port || sock, host, backlog, () => {
|
29 | if (sock) {
|
30 | ok(`Listening on ${sock} `);
|
31 | } else {
|
32 | ok(`Listening on ${host || '0.0.0.0'}:${port}`);
|
33 | }
|
34 | return this.project.hooks && this.project.hooks.onAfterListen && this.project.hooks.onAfterListen();
|
35 | });
|
36 | }
|
37 | }
|
38 |
|
39 | }
|