@@ -11,32 +11,38 @@ app.use(cors());
1111app . post ( "/generateAuthToken" , ( req , res ) => {
1212 // Extract the backend and user from the request
1313 const { backend, actAs, apiKey } = req . body ;
14+ const tokenApiPath = backend . endsWith ( "/" )
15+ ? `${ backend } rest/api/v1/createauthtoken`
16+ : `${ backend } /rest/api/v1/createauthtoken` ;
1417
1518 // Call the Glean server's createauthtoken endpoint
1619 axios ( {
1720 method : "POST" ,
18- url : ` ${ backend } /rest/api/v1/createauthtoken` ,
21+ url : tokenApiPath ,
1922 headers : {
2023 Authorization : `Bearer ${ apiKey } ` ,
2124 "X-Scio-Actas" : actAs ,
2225 accept : "application/json" ,
2326 } ,
2427 } )
2528 . then ( ( response ) => res . json ( response . data ) )
26- . catch ( ( error ) => res . status ( 500 ) . json ( { error : error . message } ) ) ;
29+ . catch ( ( error ) => res . status ( 500 ) . json ( { error : error } ) ) ;
2730} ) ;
2831
2932app . post ( "/generateAnonymousAuthToken" , ( req , res ) => {
3033 // Extract the backend and user from the request
3134 const { backend, actAs } = req . body ;
35+ const tokenApiPath = backend . endsWith ( "/" )
36+ ? `${ backend } rest/api/v1/createanonymoustoken`
37+ : `${ backend } /rest/api/v1/createanonymoustoken` ;
3238
3339 // Call the Glean server's createanonymoustoken endpoint
3440 axios ( {
3541 method : "post" ,
36- url : ` ${ backend } /api/v1/createanonymoustoken` ,
42+ url : tokenApiPath ,
3743 } )
3844 . then ( ( response ) => res . json ( response . data ) )
39- . catch ( ( error ) => res . status ( 500 ) . json ( { error : error . message } ) ) ;
45+ . catch ( ( error ) => res . status ( 500 ) . json ( { error : error } ) ) ;
4046} ) ;
4147
4248app . listen ( port , ( ) => {
0 commit comments