1 | /*
|
2 |
|
3 | ----------------------------------------------------------------------------
|
4 | | qewd: Quick and Easy Web Development |
|
5 | | |
|
6 | | Copyright (c) 2017 M/Gateway Developments Ltd, |
|
7 | | Reigate, Surrey UK. |
|
8 | | All rights reserved. |
|
9 | | |
|
10 | | http://www.mgateway.com |
|
11 | | Email: rtweed@mgateway.com |
|
12 | | |
|
13 | | |
|
14 | | Licensed under the Apache License, Version 2.0 (the "License"); |
|
15 | | you may not use this file except in compliance with the License. |
|
16 | | You may obtain a copy of the License at |
|
17 | | |
|
18 | | http://www.apache.org/licenses/LICENSE-2.0 |
|
19 | | |
|
20 | | Unless required by applicable law or agreed to in writing, software |
|
21 | | distributed under the License is distributed on an "AS IS" BASIS, |
|
22 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
23 | | See the License for the specific language governing permissions and |
|
24 | | limitations under the License. |
|
25 | ----------------------------------------------------------------------------
|
26 |
|
27 | 24 January 2017
|
28 |
|
29 | */
|
30 |
|
31 | var fs = require('fs');
|
32 | var customModulePath = '/opt/qewd/mapped/custom.js';
|
33 | var routesModulePath = '/opt/qewd/mapped/routes.js';
|
34 | var moduleMapPath = '/opt/qewd/mapped/moduleMap.js';
|
35 | var custom;
|
36 | var routes;
|
37 | if (fs.existsSync(customModulePath)) {
|
38 | custom = require(customModulePath);
|
39 | }
|
40 | if (fs.existsSync(routesModulePath)) {
|
41 | var routes = require(routesModulePath);
|
42 | }
|
43 | if (fs.existsSync(moduleMapPath)) {
|
44 | var moduleMap = require(moduleMapPath);
|
45 | }
|
46 | if (!routes) routes = [];
|
47 | if (!moduleMap) moduleMap = {};
|
48 |
|
49 | if (!custom) {
|
50 | custom = {
|
51 | config: {},
|
52 | run: function() {}
|
53 | };
|
54 | }
|
55 |
|
56 | if (custom && !custom.config) custom.config = {};
|
57 | if (custom && !custom.run) custom.run = function() {};
|
58 |
|
59 | var database = {
|
60 | type: 'redis',
|
61 | params: {
|
62 | host: process.env.REDIS_PORT_6379_TCP_ADDR,
|
63 | port: process.env.REDIS_PORT_6379_TCP_PORT
|
64 | }
|
65 | };
|
66 | if (custom.config.database) database = custom.config.database;
|
67 |
|
68 | var config = {
|
69 | managementPassword: custom.config.managementPassword || 'keepThisSecret!',
|
70 | serverName: custom.config.serverName || 'QEWD Docker Server',
|
71 | port: custom.config.port || 8080,
|
72 | poolSize: custom.config.poolSize || 1,
|
73 | database: database,
|
74 | moduleMap: moduleMap
|
75 | };
|
76 |
|
77 | var qewd = require('qewd').master;
|
78 | var q = qewd.start(config, routes);
|
79 | var intercept = qewd.intercept();
|
80 |
|
81 | custom.run(config, q, intercept);
|