new(core.gbapp): New API endpoint.
This commit is contained in:
		
							parent
							
								
									8568f62bdc
								
							
						
					
					
						commit
						367d9ead7e
					
				
					 1 changed files with 17 additions and 29 deletions
				
			
		
							
								
								
									
										46
									
								
								src/app.ts
									
										
									
									
									
								
							
							
						
						
									
										46
									
								
								src/app.ts
									
										
									
									
									
								
							| 
						 | 
					@ -114,7 +114,7 @@ export class GBServer {
 | 
				
			||||||
    process.on('uncaughtException', (err, p) => {
 | 
					    process.on('uncaughtException', (err, p) => {
 | 
				
			||||||
      if (err !== null) {
 | 
					      if (err !== null) {
 | 
				
			||||||
        err = err['e'] ? err['e'] : err;
 | 
					        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}`);
 | 
					        GBLog.error(`UNCAUGHT_EXCEPTION:  ${err.toString()} ${err['stack'] ? '\n' + err['stack'] : ''} ${msg}`);
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        GBLog.error('UNCAUGHT_EXCEPTION: Unknown error (err is null)');
 | 
					        GBLog.error('UNCAUGHT_EXCEPTION: Unknown error (err is null)');
 | 
				
			||||||
| 
						 | 
					@ -252,32 +252,10 @@ export class GBServer {
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          server.post('*', async (req, res, next) => {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            const host = req.headers.host;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Roteamento com base no domínio.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (host === process.env.API_HOST) {
 | 
					 | 
				
			||||||
              GBLog.info(`Redirecting to API...`);
 | 
					 | 
				
			||||||
              return httpProxy.web(req, res, { target: 'http://localhost:1111' }); // Express server
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await GBSSR.ssrFilter(req, res, next);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          server.get('*', async (req, res, next) => {
 | 
					          server.get('*', async (req, res, next) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const host = req.headers.host;
 | 
					            const host = req.headers.host;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Roteamento com base no domínio.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (host === process.env.API_HOST) {
 | 
					 | 
				
			||||||
              GBLog.info(`Redirecting to API...`);
 | 
					 | 
				
			||||||
              return httpProxy.web(req, res, { target: 'http://localhost:1111' }); // Express server
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (req.originalUrl.startsWith('/logs')) {
 | 
					            if (req.originalUrl.startsWith('/logs')) {
 | 
				
			||||||
              if (process.env.ENABLE_WEBLOG === "true") {
 | 
					              if (process.env.ENABLE_WEBLOG === "true") {
 | 
				
			||||||
                const admins = {
 | 
					                const admins = {
 | 
				
			||||||
| 
						 | 
					@ -312,17 +290,27 @@ export class GBServer {
 | 
				
			||||||
      })();
 | 
					      })();
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (process.env.CERTIFICATE_PFX) {
 | 
					    if (process.env.CERTIFICATE_PFX) {
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      // Setups unsecure http redirect.
 | 
					      // Setups unsecure http redirect.
 | 
				
			||||||
      
 | 
					      const proxy = httpProxy.createProxyServer({});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const server1 = http.createServer((req, res) => {
 | 
					      const server1 = http.createServer((req, res) => {
 | 
				
			||||||
        const host = req.headers.host.startsWith('www.') ?
 | 
					        const host = req.headers.host.startsWith('www.') ?
 | 
				
			||||||
          req.headers.host.substring(4) : req.headers.host;
 | 
					          req.headers.host.substring(4) : req.headers.host;
 | 
				
			||||||
        res.writeHead(301, {
 | 
					
 | 
				
			||||||
          Location: "https://" + host + req.url
 | 
					        if (host === process.env.API_HOST) {
 | 
				
			||||||
        }).end();
 | 
					          GBLog.info(`Redirecting to API...`);
 | 
				
			||||||
 | 
					          return proxy.web(req, res, { target: 'http://localhost:1111' }); // Express server
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          res.writeHead(301, {
 | 
				
			||||||
 | 
					            Location: "https://" + host + req.url
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          }).end();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      server1.listen(80);
 | 
					      server1.listen(80);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue