new(core.gbapp): New API endpoint.
This commit is contained in:
		
							parent
							
								
									7c208954f3
								
							
						
					
					
						commit
						edb50e3b13
					
				
					 1 changed files with 43 additions and 44 deletions
				
			
		
							
								
								
									
										87
									
								
								src/app.ts
									
										
									
									
									
								
							
							
						
						
									
										87
									
								
								src/app.ts
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -114,7 +114,7 @@ export class GBServer {
 | 
			
		|||
    process.on('uncaughtException', (err, p) => {
 | 
			
		||||
      if (err !== null) {
 | 
			
		||||
        err = err['e'] ? err['e'] : err;
 | 
			
		||||
        const msg = `${err['code'] ? err['code'] : ''} ${err?.['response']?.['data'] ? err?.['response']?.['data'] : ''} ${err.message ? err.message : ''} ${err['description'] ? err['description'] : ''}`
 | 
			
		||||
        const msg = `${err['code'] ? err['code'] : ''} ${err?.['response']?.['data'] ? err?.['response']?.['data']: ''} ${err.message ? err.message : ''} ${err['description'] ? err['description'] : ''}`
 | 
			
		||||
        GBLog.error(`UNCAUGHT_EXCEPTION:  ${err.toString()} ${err['stack'] ? '\n' + err['stack'] : ''} ${msg}`);
 | 
			
		||||
      } else {
 | 
			
		||||
        GBLog.error('UNCAUGHT_EXCEPTION: Unknown error (err is null)');
 | 
			
		||||
| 
						 | 
				
			
			@ -298,49 +298,6 @@ export class GBServer {
 | 
			
		|||
            }
 | 
			
		||||
          });
 | 
			
		||||
 | 
			
		||||
          // Setups unsecure http redirect.
 | 
			
		||||
 | 
			
		||||
          if (process.env.NODE_ENV === 'production') {
 | 
			
		||||
            const server1 = http.createServer((req, res) => {
 | 
			
		||||
              const host = req.headers.host.startsWith('www.') ?
 | 
			
		||||
                req.headers.host.substring(4) : req.headers.host;
 | 
			
		||||
              res.writeHead(301, {
 | 
			
		||||
                Location: "https://" + host + req.url
 | 
			
		||||
              }).end();
 | 
			
		||||
            });
 | 
			
		||||
            server1.listen(80);
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          if (process.env.CERTIFICATE_PFX) {
 | 
			
		||||
 | 
			
		||||
            const options1 = {
 | 
			
		||||
              passphrase: process.env.CERTIFICATE_PASSPHRASE,
 | 
			
		||||
              pfx: fs.readFileSync(process.env.CERTIFICATE_PFX)
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
 | 
			
		||||
            GBServer.globals.httpsServer = httpsServer;
 | 
			
		||||
 | 
			
		||||
            for (let i = 2; ; i++) {
 | 
			
		||||
              const certPfxEnv = `CERTIFICATE${i}_PFX`;
 | 
			
		||||
              const certPassphraseEnv = `CERTIFICATE${i}_PASSPHRASE`;
 | 
			
		||||
              const certDomainEnv = `CERTIFICATE${i}_DOMAIN`;
 | 
			
		||||
 | 
			
		||||
              if (process.env[certPfxEnv] && process.env[certPassphraseEnv] && process.env[certDomainEnv]) {
 | 
			
		||||
                const options = {
 | 
			
		||||
                  passphrase: process.env[certPassphraseEnv],
 | 
			
		||||
                  pfx: fs.readFileSync(process.env[certPfxEnv])
 | 
			
		||||
                };
 | 
			
		||||
                httpsServer.addContext(process.env[certDomainEnv], options);
 | 
			
		||||
              } else {
 | 
			
		||||
                break;
 | 
			
		||||
              }
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          else {
 | 
			
		||||
            server.listen(port, mainCallback);
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          GBLog.info(`The Bot Server is in RUNNING mode...`);
 | 
			
		||||
 | 
			
		||||
          // Opens Navigator.
 | 
			
		||||
| 
						 | 
				
			
			@ -355,6 +312,48 @@ export class GBServer {
 | 
			
		|||
      })();
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Setups unsecure http redirect.
 | 
			
		||||
 | 
			
		||||
    if (process.env.NODE_ENV === 'production') {
 | 
			
		||||
      const server1 = http.createServer((req, res) => {
 | 
			
		||||
        const host = req.headers.host.startsWith('www.') ?
 | 
			
		||||
          req.headers.host.substring(4) : req.headers.host;
 | 
			
		||||
        res.writeHead(301, {
 | 
			
		||||
          Location: "https://" + host + req.url
 | 
			
		||||
        }).end();
 | 
			
		||||
      });
 | 
			
		||||
      server1.listen(80);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (process.env.CERTIFICATE_PFX) {
 | 
			
		||||
 | 
			
		||||
      const options1 = {
 | 
			
		||||
        passphrase: process.env.CERTIFICATE_PASSPHRASE,
 | 
			
		||||
        pfx: fs.readFileSync(process.env.CERTIFICATE_PFX)
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
 | 
			
		||||
      GBServer.globals.httpsServer = httpsServer;
 | 
			
		||||
 | 
			
		||||
      for (let i = 2; ; i++) {
 | 
			
		||||
        const certPfxEnv = `CERTIFICATE${i}_PFX`;
 | 
			
		||||
        const certPassphraseEnv = `CERTIFICATE${i}_PASSPHRASE`;
 | 
			
		||||
        const certDomainEnv = `CERTIFICATE${i}_DOMAIN`;
 | 
			
		||||
 | 
			
		||||
        if (process.env[certPfxEnv] && process.env[certPassphraseEnv] && process.env[certDomainEnv]) {
 | 
			
		||||
          const options = {
 | 
			
		||||
            passphrase: process.env[certPassphraseEnv],
 | 
			
		||||
            pfx: fs.readFileSync(process.env[certPfxEnv])
 | 
			
		||||
          };
 | 
			
		||||
          httpsServer.addContext(process.env[certDomainEnv], options);
 | 
			
		||||
        } else {
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      server.listen(port, mainCallback);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static initEndpointsDocs(app: express.Application) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue