1- const express = require ( 'express' ) ;
2- const bodyParser = require ( 'body-parser' ) ;
3- const http = require ( 'http' ) ;
4- const https = require ( 'https' ) ;
5- const fs = require ( 'fs' ) ;
6- const path = require ( 'path' ) ;
7- const router = require ( './routes' ) . router ;
8- const config = require ( '../config' ) ;
9- const db = require ( '../db' ) ;
10- const { PluginLoader } = require ( '../plugin' ) ;
11- const chain = require ( './chain' ) ;
1+ import express from 'express' ;
2+ import bodyParser from 'body-parser' ;
3+ import http from 'http' ;
4+ import https from 'https' ;
5+ import fs from 'fs' ;
6+ import path from 'path' ;
7+ import { router } from './routes' ;
8+ import {
9+ getAuthorisedList ,
10+ getPlugins ,
11+ getSSLCertPath ,
12+ getSSLKeyPath
13+ } from '../config' ;
14+ import {
15+ addUserCanAuthorise ,
16+ addUserCanPush ,
17+ createRepo ,
18+ getRepos
19+ } from '../db' ;
20+ import { PluginLoader } from '../plugin' ;
21+ import chain from './chain' ;
22+ import { Repo } from '../db/types' ;
23+
1224const { GIT_PROXY_SERVER_PORT : proxyHttpPort , GIT_PROXY_HTTPS_SERVER_PORT : proxyHttpsPort } =
1325 require ( '../config/env' ) . serverConfig ;
1426
1527const options = {
1628 inflate : true ,
1729 limit : '100000kb' ,
1830 type : '*/*' ,
19- key : fs . readFileSync ( path . join ( __dirname , config . getSSLKeyPath ( ) ) ) ,
20- cert : fs . readFileSync ( path . join ( __dirname , config . getSSLCertPath ( ) ) ) ,
31+ key : fs . readFileSync ( path . join ( __dirname , getSSLKeyPath ( ) ) ) ,
32+ cert : fs . readFileSync ( path . join ( __dirname , getSSLCertPath ( ) ) ) ,
2133} ;
2234
2335const proxyPreparations = async ( ) => {
24- const plugins = config . getPlugins ( ) ;
36+ const plugins = getPlugins ( ) ;
2537 const pluginLoader = new PluginLoader ( plugins ) ;
2638 await pluginLoader . load ( ) ;
2739 chain . chainPluginLoader = pluginLoader ;
2840 // Check to see if the default repos are in the repo list
29- const defaultAuthorisedRepoList = config . getAuthorisedList ( ) ;
30- const allowedList = await db . getRepos ( ) ;
41+ const defaultAuthorisedRepoList = getAuthorisedList ( ) ;
42+ const allowedList : Repo [ ] = await getRepos ( ) ;
3143
3244 defaultAuthorisedRepoList . forEach ( async ( x ) => {
3345 const found = allowedList . find ( ( y ) => y . project === x . project && x . name === y . name ) ;
3446 if ( ! found ) {
35- await db . createRepo ( x ) ;
36- await db . addUserCanPush ( x . name , 'admin' ) ;
37- await db . addUserCanAuthorise ( x . name , 'admin' ) ;
47+ await createRepo ( x ) ;
48+ await addUserCanPush ( x . name , 'admin' ) ;
49+ await addUserCanAuthorise ( x . name , 'admin' ) ;
3850 }
3951 } ) ;
4052} ;
@@ -51,7 +63,7 @@ const createApp = async () => {
5163const start = async ( ) => {
5264 const app = await createApp ( ) ;
5365 await proxyPreparations ( ) ;
54- http . createServer ( options , app ) . listen ( proxyHttpPort , ( ) => {
66+ http . createServer ( options as any , app ) . listen ( proxyHttpPort , ( ) => {
5567 console . log ( `HTTP Proxy Listening on ${ proxyHttpPort } ` ) ;
5668 } ) ;
5769 https . createServer ( options , app ) . listen ( proxyHttpsPort , ( ) => {
@@ -61,6 +73,8 @@ const start = async () => {
6173 return app ;
6274} ;
6375
64- module . exports . proxyPreparations = proxyPreparations ;
65- module . exports . createApp = createApp ;
66- module . exports . start = start ;
76+ export {
77+ proxyPreparations ,
78+ createApp ,
79+ start
80+ } ;
0 commit comments