1- const proxyApp = require ( 'express' ) ( ) ;
1+ const express = require ( 'express' ) ;
22const bodyParser = require ( 'body-parser' ) ;
3- const http = require ( " http" ) ;
4- const https = require ( " https" ) ;
3+ const http = require ( ' http' ) ;
4+ const https = require ( ' https' ) ;
55const fs = require ( 'fs' ) ;
6- const path = require ( " path" ) ;
6+ const path = require ( ' path' ) ;
77const router = require ( './routes' ) . router ;
88const config = require ( '../config' ) ;
99const db = require ( '../db' ) ;
@@ -17,18 +17,14 @@ const options = {
1717 limit : '100000kb' ,
1818 type : '*/*' ,
1919 key : fs . readFileSync ( path . join ( __dirname , config . getSSLKeyPath ( ) ) ) ,
20- cert : fs . readFileSync ( path . join ( __dirname , config . getSSLCertPath ( ) ) )
20+ cert : fs . readFileSync ( path . join ( __dirname , config . getSSLCertPath ( ) ) ) ,
2121} ;
2222
23- // Setup the proxy middleware
24- proxyApp . use ( bodyParser . raw ( options ) ) ;
25- proxyApp . use ( '/' , router ) ;
26-
27- const start = async ( ) => {
28- const plugins = config . getPlugins ( ) ;
29- const pluginLoader = new PluginLoader ( plugins ) ;
30- await pluginLoader . load ( ) ;
31- chain . chainPluginLoader = pluginLoader ;
23+ const proxyPreparations = async ( ) => {
24+ const plugins = config . getPlugins ( ) ;
25+ const pluginLoader = new PluginLoader ( plugins ) ;
26+ await pluginLoader . load ( ) ;
27+ chain . chainPluginLoader = pluginLoader ;
3228 // Check to see if the default repos are in the repo list
3329 const defaultAuthorisedRepoList = config . getAuthorisedList ( ) ;
3430 const allowedList = await db . getRepos ( ) ;
@@ -41,15 +37,30 @@ const start = async () => {
4137 await db . addUserCanAuthorise ( x . name , 'admin' ) ;
4238 }
4339 } ) ;
40+ } ;
4441
45- http . createServer ( options , proxyApp ) . listen ( proxyHttpPort , ( ) => {
42+ // just keep this async incase it needs async stuff in the future
43+ const createApp = async ( ) => {
44+ const app = express ( ) ;
45+ // Setup the proxy middleware
46+ app . use ( bodyParser . raw ( options ) ) ;
47+ app . use ( '/' , router ) ;
48+ return app ;
49+ } ;
50+
51+ const start = async ( ) => {
52+ const app = await createApp ( ) ;
53+ await proxyPreparations ( ) ;
54+ http . createServer ( options , app ) . listen ( proxyHttpPort , ( ) => {
4655 console . log ( `HTTP Proxy Listening on ${ proxyHttpPort } ` ) ;
4756 } ) ;
48- https . createServer ( options , proxyApp ) . listen ( proxyHttpsPort , ( ) => {
57+ https . createServer ( options , app ) . listen ( proxyHttpsPort , ( ) => {
4958 console . log ( `HTTPS Proxy Listening on ${ proxyHttpsPort } ` ) ;
5059 } ) ;
5160
52- return proxyApp ;
61+ return app ;
5362} ;
5463
64+ module . exports . proxyPreparations = proxyPreparations ;
65+ module . exports . createApp = createApp ;
5566module . exports . start = start ;
0 commit comments