new(core.gbapp): New API endpoint.

This commit is contained in:
Rodrigo Rodriguez 2024-04-17 13:12:04 -03:00
parent 8568f62bdc
commit 367d9ead7e

View file

@ -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 = {
@ -316,13 +294,23 @@ 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;
if (host === process.env.API_HOST) {
GBLog.info(`Redirecting to API...`);
return proxy.web(req, res, { target: 'http://localhost:1111' }); // Express server
}
else {
res.writeHead(301, { res.writeHead(301, {
Location: "https://" + host + req.url Location: "https://" + host + req.url
}).end(); }).end();
}
}); });
server1.listen(80); server1.listen(80);