UNPKG

3.23 kBJavaScriptView Raw
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
31var fs = require('fs');
32var customModulePath = '/opt/qewd/mapped/custom.js';
33var routesModulePath = '/opt/qewd/mapped/routes.js';
34var moduleMapPath = '/opt/qewd/mapped/moduleMap.js';
35var custom;
36var routes;
37if (fs.existsSync(customModulePath)) {
38 custom = require(customModulePath);
39}
40if (fs.existsSync(routesModulePath)) {
41 var routes = require(routesModulePath);
42}
43if (fs.existsSync(moduleMapPath)) {
44 var moduleMap = require(moduleMapPath);
45}
46if (!routes) routes = [];
47if (!moduleMap) moduleMap = {};
48
49if (!custom) {
50 custom = {
51 config: {},
52 run: function() {}
53 };
54}
55
56if (custom && !custom.config) custom.config = {};
57if (custom && !custom.run) custom.run = function() {};
58
59var 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};
66if (custom.config.database) database = custom.config.database;
67
68var 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
77var qewd = require('qewd').master;
78var q = qewd.start(config, routes);
79var intercept = qewd.intercept();
80
81custom.run(config, q, intercept);