1
- const proxyApp = require ( 'express' ) ( ) ;
1
+ const express = require ( 'express' ) ;
2
2
const bodyParser = require ( 'body-parser' ) ;
3
- const http = require ( " http" ) ;
4
- const https = require ( " https" ) ;
3
+ const http = require ( ' http' ) ;
4
+ const https = require ( ' https' ) ;
5
5
const fs = require ( 'fs' ) ;
6
- const path = require ( " path" ) ;
6
+ const path = require ( ' path' ) ;
7
7
const router = require ( './routes' ) . router ;
8
8
const config = require ( '../config' ) ;
9
9
const db = require ( '../db' ) ;
@@ -17,18 +17,14 @@ const options = {
17
17
limit : '100000kb' ,
18
18
type : '*/*' ,
19
19
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 ( ) ) ) ,
21
21
} ;
22
22
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 ;
32
28
// Check to see if the default repos are in the repo list
33
29
const defaultAuthorisedRepoList = config . getAuthorisedList ( ) ;
34
30
const allowedList = await db . getRepos ( ) ;
@@ -41,15 +37,30 @@ const start = async () => {
41
37
await db . addUserCanAuthorise ( x . name , 'admin' ) ;
42
38
}
43
39
} ) ;
40
+ } ;
44
41
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 , ( ) => {
46
55
console . log ( `HTTP Proxy Listening on ${ proxyHttpPort } ` ) ;
47
56
} ) ;
48
- https . createServer ( options , proxyApp ) . listen ( proxyHttpsPort , ( ) => {
57
+ https . createServer ( options , app ) . listen ( proxyHttpsPort , ( ) => {
49
58
console . log ( `HTTPS Proxy Listening on ${ proxyHttpsPort } ` ) ;
50
59
} ) ;
51
60
52
- return proxyApp ;
61
+ return app ;
53
62
} ;
54
63
64
+ module . exports . proxyPreparations = proxyPreparations ;
65
+ module . exports . createApp = createApp ;
55
66
module . exports . start = start ;
0 commit comments