@@ -10,7 +10,7 @@ import { AppContext, Repository } from "./types.js";
10
10
import { cloneRepository , fetchRepository } from "./git.js" ;
11
11
import { createLogger } from "./logger.js" ;
12
12
import { createRepository , Database , loadDB , updateRepository } from './db.js' ;
13
- import { measure } from "./utils.js" ;
13
+ import { isRemotePath , measure } from "./utils.js" ;
14
14
import { REINDEX_INTERVAL_MS , RESYNC_CONFIG_INTERVAL_MS } from "./constants.js" ;
15
15
import stripJsonComments from 'strip-json-comments' ;
16
16
@@ -41,10 +41,22 @@ const indexRepository = async (repo: Repository, ctx: AppContext) => {
41
41
}
42
42
43
43
const syncConfig = async ( configPath : string , db : Database , signal : AbortSignal , ctx : AppContext ) => {
44
- const configContent = await readFile ( configPath , {
45
- encoding : 'utf-8' ,
46
- signal,
47
- } ) ;
44
+ const configContent = await ( async ( ) => {
45
+ if ( isRemotePath ( configPath ) ) {
46
+ const response = await fetch ( configPath , {
47
+ signal,
48
+ } ) ;
49
+ if ( ! response . ok ) {
50
+ throw new Error ( `Failed to fetch config file ${ configPath } : ${ response . statusText } ` ) ;
51
+ }
52
+ return response . text ( ) ;
53
+ } else {
54
+ return readFile ( configPath , {
55
+ encoding : 'utf-8' ,
56
+ signal,
57
+ } ) ;
58
+ }
59
+ } ) ( ) ;
48
60
49
61
// @todo : we should validate the configuration file's structure here.
50
62
const config = JSON . parse ( stripJsonComments ( configContent ) ) as SourcebotConfigurationSchema ;
@@ -122,7 +134,7 @@ const syncConfig = async (configPath: string, db: Database, signal: AbortSignal,
122
134
} ) ;
123
135
const args = parser . parse_args ( ) as Arguments ;
124
136
125
- if ( ! existsSync ( args . configPath ) ) {
137
+ if ( ! isRemotePath ( args . configPath ) && ! existsSync ( args . configPath ) ) {
126
138
console . error ( `Config file ${ args . configPath } does not exist` ) ;
127
139
process . exit ( 1 ) ;
128
140
}
@@ -173,11 +185,13 @@ const syncConfig = async (configPath: string, db: Database, signal: AbortSignal,
173
185
} ) ;
174
186
}
175
187
176
- // Re-sync on file changes
177
- watch ( args . configPath , ( ) => {
178
- logger . info ( `Config file ${ args . configPath } changed. Re-syncing...` ) ;
179
- _syncConfig ( ) ;
180
- } ) ;
188
+ // Re-sync on file changes if the config file is local
189
+ if ( ! isRemotePath ( args . configPath ) ) {
190
+ watch ( args . configPath , ( ) => {
191
+ logger . info ( `Config file ${ args . configPath } changed. Re-syncing...` ) ;
192
+ _syncConfig ( ) ;
193
+ } ) ;
194
+ }
181
195
182
196
// Re-sync every 24 hours
183
197
setInterval ( ( ) => {
0 commit comments