new(core.gbapp): New API endpoint.
This commit is contained in:
parent
367d9ead7e
commit
dab7239f32
1 changed files with 14 additions and 15 deletions
21
src/app.ts
21
src/app.ts
|
@ -252,7 +252,7 @@ export class GBServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
server.get('*', async (req, res, next) => {
|
server.all('*', async (req, res, next) => {
|
||||||
|
|
||||||
const host = req.headers.host;
|
const host = req.headers.host;
|
||||||
|
|
||||||
|
@ -272,8 +272,17 @@ export class GBServer {
|
||||||
await GBSSR.ssrFilter(req, res, next);
|
await GBSSR.ssrFilter(req, res, next);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// Setups unsecure http redirect.
|
||||||
|
const proxy = httpProxy.createProxyServer({});
|
||||||
|
|
||||||
|
if (host === process.env.API_HOST) {
|
||||||
|
GBLog.info(`Redirecting to API...`);
|
||||||
|
return proxy.web(req, res, { target: 'http://localhost:1111' }); // Express server
|
||||||
|
} else {
|
||||||
await GBSSR.ssrFilter(req, res, next);
|
await GBSSR.ssrFilter(req, res, next);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
GBLog.info(`The Bot Server is in RUNNING mode...`);
|
GBLog.info(`The Bot Server is in RUNNING mode...`);
|
||||||
|
@ -293,24 +302,14 @@ export class GBServer {
|
||||||
|
|
||||||
if (process.env.CERTIFICATE_PFX) {
|
if (process.env.CERTIFICATE_PFX) {
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue