@@ -10,7 +10,7 @@ import { AppContext, Repository } from "./types.js";
1010import { cloneRepository , fetchRepository } from "./git.js" ;
1111import { createLogger } from "./logger.js" ;
1212import { createRepository , Database , loadDB , updateRepository } from './db.js' ;
13- import { measure } from "./utils.js" ;
13+ import { isRemotePath , measure } from "./utils.js" ;
1414import { REINDEX_INTERVAL_MS , RESYNC_CONFIG_INTERVAL_MS } from "./constants.js" ;
1515import stripJsonComments from 'strip-json-comments' ;
1616
@@ -41,10 +41,22 @@ const indexRepository = async (repo: Repository, ctx: AppContext) => {
4141}
4242
4343const 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+ } ) ( ) ;
4860
4961 // @todo : we should validate the configuration file's structure here.
5062 const config = JSON . parse ( stripJsonComments ( configContent ) ) as SourcebotConfigurationSchema ;
@@ -122,7 +134,7 @@ const syncConfig = async (configPath: string, db: Database, signal: AbortSignal,
122134 } ) ;
123135 const args = parser . parse_args ( ) as Arguments ;
124136
125- if ( ! existsSync ( args . configPath ) ) {
137+ if ( ! isRemotePath ( args . configPath ) && ! existsSync ( args . configPath ) ) {
126138 console . error ( `Config file ${ args . configPath } does not exist` ) ;
127139 process . exit ( 1 ) ;
128140 }
@@ -173,11 +185,13 @@ const syncConfig = async (configPath: string, db: Database, signal: AbortSignal,
173185 } ) ;
174186 }
175187
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+ }
181195
182196 // Re-sync every 24 hours
183197 setInterval ( ( ) => {
0 commit comments