@@ -10,8 +10,9 @@ import { getLog, GetLogOptions } from "./helpers/get-log";
1010import { readCliOptions } from "./bin/read-cli-options" ;
1111import { readEnvOptions } from "./bin/read-env-options" ;
1212import { Server , ServerOptions } from "./server/server" ;
13- import { load } from "./load" ;
1413import { defaultApp } from "./apps/default" ;
14+ import { resolveAppFunction } from "./helpers/resolve-app-function" ;
15+ import { load } from "./load" ;
1516
1617type AdditionalOptions = {
1718 env : Record < string , string | undefined > ;
@@ -39,7 +40,7 @@ export async function run(
3940 webhookProxy,
4041
4142 // probot options
42- id ,
43+ appId ,
4344 privateKey,
4445 redisConfig,
4546 secret,
@@ -61,30 +62,28 @@ export async function run(
6162 const log = getLog ( logOptions ) ;
6263 logWarningsForObsoleteEnvironmentVariables ( log ) ;
6364
65+ const probotOptions : Options = {
66+ appId,
67+ privateKey,
68+ redisConfig,
69+ secret,
70+ baseUrl,
71+ log : log . child ( { name : "probot" } ) ,
72+ } ;
6473 const serverOptions : ServerOptions = {
6574 host,
6675 port,
6776 webhookPath,
6877 webhookProxy,
6978 log : log . child ( { name : "server" } ) ,
79+ Probot : Probot . defaults ( probotOptions ) ,
7080 } ;
7181
72- const server = new Server ( serverOptions ) ;
73- const router = server . router ( ) ;
74-
75- const probotOptions : Options = {
76- id,
77- privateKey,
78- redisConfig,
79- secret,
80- baseUrl,
81- log : log . child ( { name : "probot" } ) ,
82- } ;
83- const probot = new Probot ( probotOptions ) ;
82+ let server : Server ;
8483
85- if ( ! id || ! privateKey ) {
84+ if ( ! appId || ! privateKey ) {
8685 if ( process . env . NODE_ENV === "production" ) {
87- if ( ! id ) {
86+ if ( ! appId ) {
8887 throw new Error (
8988 "Application ID is missing, and is required to run in production mode. " +
9089 "To resolve, ensure the APP_ID environment variable is set."
@@ -96,27 +95,35 @@ export async function run(
9695 ) ;
9796 }
9897 }
99- load ( probot , router , setupAppFactory ( host , port ) ) ;
100- } else if ( Array . isArray ( appFnOrArgv ) ) {
101- const pkg = await pkgConf ( "probot" ) ;
102- load ( probot , router , defaultApp ) ;
98+ server = new Server ( setupAppFactory ( host , port ) , serverOptions ) ;
99+ await server . start ( ) ;
100+ return server ;
101+ }
103102
104- if ( Array . isArray ( pkg . apps ) ) {
105- for ( const app of pkg . apps ) {
106- load ( probot , router , app ) ;
107- }
108- }
103+ if ( Array . isArray ( appFnOrArgv ) ) {
104+ const pkg = await pkgConf ( "probot" ) ;
109105
110- const [ appFn ] = args ;
106+ const combinedApps : ApplicationFunction = ( { app } ) => {
107+ load ( app , server . router ( ) , defaultApp ) ;
111108
112- load ( probot , router , appFn ) ;
109+ if ( Array . isArray ( pkg . apps ) ) {
110+ for ( const appPath of pkg . apps ) {
111+ const appFn = resolveAppFunction ( appPath ) ;
112+ load ( app , server . router ( ) , appFn ) ;
113+ }
114+ }
113115
114- server . app . use ( webhookPath ? webhookPath : "/" , probot . webhooks . middleware ) ;
115- } else {
116- load ( probot , router , appFnOrArgv ) ;
116+ const [ appPath ] = args ;
117+ const appFn = resolveAppFunction ( appPath ) ;
118+ load ( app , server . router ( ) , appFn ) ;
119+ } ;
117120
118- server . app . use ( webhookPath ? webhookPath : "/" , probot . webhooks . middleware ) ;
121+ server = new Server ( combinedApps , serverOptions ) ;
122+ await server . start ( ) ;
123+ return server ;
119124 }
125+
126+ server = new Server ( appFnOrArgv , serverOptions ) ;
120127 await server . start ( ) ;
121128
122129 return server ;
0 commit comments