44 *
55 * SPDX-License-Identifier: MIT
66 ********************************************************************************/
7- const express = require ( 'express' ) ;
8- const router = express . Router ( ) ;
9- const mime = require ( 'mime-types' ) ;
10- const dns = require ( 'dns' ) ;
11-
7+ const express = require ( 'express' ) ;
8+ const router = express . Router ( ) ;
9+ const mime = require ( 'mime-types' ) ;
10+ const organizations = new Map ( ) ;
11+
1212class CoCreateFileSystem {
1313 constructor ( crud , render ) {
1414 this . router = router . get ( '/*' , async ( req , res ) => {
15- let organization_id ;
1615 let hostname = req . hostname ;
16+
17+ let organization_id = organizations . get ( hostname ) ;
18+ console . log ( req . protocol , req . secure )
19+ // let ddns = await certManager.checkDns(hostname)
20+ // let hasCert = await certManager.checkCert(hostname)
21+ // console.log(hostname, 'crt==', hasCert)
22+ // ToDo: check if secured domain by running command
23+ // sudo certbot certificates using spawn
24+ // console.dir(req.headers.host)
1725 // dns.resolve(hostname, 'TXT', (err, records) => {
1826 // if (records)
1927 // organization_id = records[0][0];
2028 // if (err)
2129 // console.log(hostname, err);
2230 // });
23-
31+
32+
2433 if ( ! organization_id ) {
2534 let organization = await crud . readDocument ( {
2635 collection : 'organizations' ,
@@ -32,9 +41,10 @@ class CoCreateFileSystem {
3241 organization_id : process . env . organization_id
3342 } )
3443 if ( ! organization || ! organization . document || ! organization . document [ 0 ] )
35- return res . send ( 'Organization cannot be found using the host: ' + hostname + ' in platformDB: ' + process . env . organization_id ) ;
44+ return res . send ( 'Organization cannot be found using the host--- : ' + hostname + ' in platformDB: ' + process . env . organization_id ) ;
3645
3746 organization_id = organization . document [ 0 ] . _id
47+ organizations . set ( hostname , organization_id )
3848 }
3949
4050 let [ url , parameters ] = req . url . split ( "?" ) ;
0 commit comments