@@ -22,48 +22,62 @@ async function connectionSettings(req, res) {
2222 if ( req . headers && req . headers . referer && ! req . headers . referer . includes ( '/sites/' ) ) {
2323 baseAPIPath = HAXCMS . systemRequestBase ;
2424 }
25+ var sitename = '' ;
2526 // express gives this up on requests but doesn't know it ahead of time
2627 if ( req . headers && req . headers . referer ) {
2728 let details = new url . URL ( req . headers . referer ) ;
2829 HAXCMS . protocol = details . protocol . replace ( ':' , '' ) ;
2930 HAXCMS . domain = details . host ;
3031 HAXCMS . request_url = details ;
32+
33+ const sitepath = req . headers . referer . replace ( `${ HAXCMS . protocol } ://${ HAXCMS . domain } ${ HAXCMS . basePath } ${ HAXCMS . sitesDirectory } /` , '' ) ;
34+ const siteparts = sitepath . split ( '/' ) ;
35+ // should always be at the base here
36+ sitename = siteparts [ 0 ] ;
3137 }
38+ const siteToken = HAXCMS . getRequestToken ( HAXCMS . getActiveUserName ( ) + ':' + sitename ) ;
39+ // user token is just the name of the logged in user
40+ const userToken = HAXCMS . getRequestToken ( HAXCMS . getActiveUserName ( ) ) ;
3241 const returnData = JSON . stringify ( {
3342 token : HAXCMS . getRequestToken ( ) ,
43+ login : `${ baseAPIPath } login` ,
44+ refreshUrl : `${ baseAPIPath } refreshAccessToken` ,
45+ logout : `${ baseAPIPath } logout` ,
46+ connectionSettings : `${ baseAPIPath } connectionSettings` ,
47+ // enables redirecting back to site root if JWT really is dead
48+ redirectUrl : HAXCMS . basePath ,
49+ saveNodePath : `${ baseAPIPath } saveNode?site_token=${ siteToken } ` ,
50+ saveManifestPath : `${ baseAPIPath } saveManifest?site_token=${ siteToken } ` ,
51+ saveOutlinePath : `${ baseAPIPath } saveOutline?site_token=${ siteToken } ` ,
52+ getSiteFieldsPath : `${ baseAPIPath } formLoad?haxcms_form_id=siteSettings` ,
53+ // form token to validate form submissions as unique to the session
3454 getFormToken : HAXCMS . getRequestToken ( 'form' ) ,
55+ createNodePath : `${ baseAPIPath } createNode?site_token=${ siteToken } ` ,
56+ deleteNodePath : `${ baseAPIPath } deleteNode?site_token=${ siteToken } ` ,
57+
58+ getUserDataPath : `${ baseAPIPath } getUserData?user_token=${ userToken } ` ,
59+ createSite : `${ baseAPIPath } createSite?user_token=${ userToken } ` ,
60+ downloadSite : `${ baseAPIPath } downloadSite?user_token=${ userToken } ` ,
61+ archiveSite : `${ baseAPIPath } archiveSite?user_token=${ userToken } ` ,
62+ copySite : `${ baseAPIPath } cloneSite?user_token=${ userToken } ` ,
63+ getSitesList : `${ baseAPIPath } listSites?user_token=${ userToken } ` ,
3564 appStore : {
3665 url : `${ baseAPIPath } generateAppStore` ,
3766 params : {
38- "app-store-token" : HAXCMS . getRequestToken ( 'appstore' ) ,
67+ 'appstore_token' : HAXCMS . getRequestToken ( 'appstore' ) ,
68+ 'site_token' : siteToken ,
69+ 'siteName' : sitename ,
3970 }
4071 } ,
4172 themes : themes ,
42- connectionSettings : `${ baseAPIPath } connectionSettings` ,
43- login : `${ baseAPIPath } login` ,
44- refreshUrl : `${ baseAPIPath } refreshAccessToken` ,
45- logout : `${ baseAPIPath } logout` ,
46- redirectUrl : HAXCMS . basePath ,
47- saveNodePath : `${ baseAPIPath } saveNode` ,
48- saveManifestPath : `${ baseAPIPath } saveManifest` ,
49- saveOutlinePath : `${ baseAPIPath } saveOutline` ,
50- getSiteFieldsPath : `${ baseAPIPath } formLoad?haxcms_form_id=siteSettings` ,
51- createNodePath : `${ baseAPIPath } createNode` ,
52- getUserDataPath : `${ baseAPIPath } getUserData` ,
53- deleteNodePath : `${ baseAPIPath } deleteNode` ,
54- createSite : `${ baseAPIPath } createSite` ,
55- downloadSite : `${ baseAPIPath } downloadSite` ,
56- archiveSite : `${ baseAPIPath } archiveSite` ,
57- copySite : `${ baseAPIPath } cloneSite` ,
58- getSitesList : `${ baseAPIPath } listSites` ,
5973 } ) ;
60- let after ;
74+ let after = '' ;
6175 if ( HAXCMS . HAXCMS_DISABLE_JWT_CHECKS ) {
6276 after = `window.appSettings.jwt = "${ HAXCMS . getJWT ( HAXCMS . superUser . name ) } "` ;
6377 }
6478 res . send ( `// force vercel calls to go from production
6579 window.MicroFrontendRegistryConfig = window.MicroFrontendRegistryConfig || {};
66- window.MicroFrontendRegistryConfig.base = "https://haxapi.vercel.app ";window.appSettings =${ returnData } ;${ after } ` ) ;
80+ window.MicroFrontendRegistryConfig.base = "https://open-apis.hax.cloud ";window.appSettings =${ returnData } ;${ after } ` ) ;
6781}
6882
6983module . exports = connectionSettings ;
0 commit comments