fix(core.gbapp): FIX SSR errors and setOption impersonated.
This commit is contained in:
parent
979687f20a
commit
a585cf51ea
1 changed files with 15 additions and 18 deletions
|
@ -125,11 +125,10 @@ export class GBSSR {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static async createBrowser(profilePath): Promise<any> {
|
public static async createBrowser(profilePath): Promise<any> {
|
||||||
const opts = this.preparePuppeteer(profilePath);
|
const opts = this.preparePuppeteer(profilePath);
|
||||||
puppeteer.use(hidden());
|
puppeteer.use(hidden());
|
||||||
puppeteer.use(require("puppeteer-extra-plugin-minmax")());
|
puppeteer.use(require('puppeteer-extra-plugin-minmax')());
|
||||||
const browser = await puppeteer.launch(opts);
|
const browser = await puppeteer.launch(opts);
|
||||||
return browser;
|
return browser;
|
||||||
}
|
}
|
||||||
|
@ -284,26 +283,27 @@ export class GBSSR {
|
||||||
// Tries to find botId from URL.
|
// Tries to find botId from URL.
|
||||||
|
|
||||||
const minBoot = GBServer.globals.minBoot;
|
const minBoot = GBServer.globals.minBoot;
|
||||||
let botId =
|
|
||||||
req.originalUrl && req.originalUrl === '/' ?
|
const onlyChars = /\/([A-Za-z0-9\-\_]+)\/*/.exec(req.originalUrl);
|
||||||
minBoot.botId :
|
|
||||||
/\/([A-Za-z0-9\-\_]+)\/*/.exec(req.originalUrl)[1]
|
let botId = (req.originalUrl && req.originalUrl === '/') || onlyChars.length === 0 ? minBoot.botId : onlyChars[1];
|
||||||
|
|
||||||
let min: GBMinInstance =
|
let min: GBMinInstance =
|
||||||
req.url === '/'
|
req.url === '/'
|
||||||
? minBoot
|
? minBoot
|
||||||
: GBServer.globals.minInstances.filter(p => p.instance.botId.toLowerCase() === botId.toLowerCase())[0];
|
: GBServer.globals.minInstances.filter(p => p.instance.botId.toLowerCase() === botId.toLowerCase())[0];
|
||||||
if (!min) {
|
if (!min) {
|
||||||
min = req.url === '/'
|
min =
|
||||||
? minBoot
|
req.url === '/'
|
||||||
: GBServer.globals.minInstances.filter(p =>
|
? minBoot
|
||||||
p.instance.activationCode ? p.instance.activationCode.toLowerCase() === botId.toLowerCase()
|
: GBServer.globals.minInstances.filter(p =>
|
||||||
: null)[0];
|
p.instance.activationCode ? p.instance.activationCode.toLowerCase() === botId.toLowerCase() : null
|
||||||
|
)[0];
|
||||||
}
|
}
|
||||||
if (!min) {
|
if (!min) {
|
||||||
botId = minBoot.botId;
|
botId = minBoot.botId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let path = DialogKeywords.getGBAIPath(botId, `gbui`);
|
let path = DialogKeywords.getGBAIPath(botId, `gbui`);
|
||||||
|
|
||||||
// Checks if the bot has an .gbui published or use default.gbui.
|
// Checks if the bot has an .gbui published or use default.gbui.
|
||||||
|
@ -315,7 +315,6 @@ export class GBSSR {
|
||||||
let url = parts[0];
|
let url = parts[0];
|
||||||
|
|
||||||
if (min && req.originalUrl && prerender && exclude) {
|
if (min && req.originalUrl && prerender && exclude) {
|
||||||
|
|
||||||
// Reads from static HTML when a bot is crawling.
|
// Reads from static HTML when a bot is crawling.
|
||||||
|
|
||||||
path = Path.join(process.env.PWD, 'work', path, 'index.html');
|
path = Path.join(process.env.PWD, 'work', path, 'index.html');
|
||||||
|
@ -323,7 +322,6 @@ export class GBSSR {
|
||||||
res.status(200).send(html);
|
res.status(200).send(html);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Servers default.gbui web application.
|
// Servers default.gbui web application.
|
||||||
|
|
||||||
path = Path.join(
|
path = Path.join(
|
||||||
|
@ -334,18 +332,17 @@ export class GBSSR {
|
||||||
url === '/' || url === '' ? `index.html` : url
|
url === '/' || url === '' ? `index.html` : url
|
||||||
);
|
);
|
||||||
if (GBServer.globals.wwwroot && url === '/') {
|
if (GBServer.globals.wwwroot && url === '/') {
|
||||||
path = GBServer.globals.wwwroot + "/index.html"; // TODO.
|
path = GBServer.globals.wwwroot + '/index.html'; // TODO.
|
||||||
}
|
}
|
||||||
if (!min && !url.startsWith("/static") && GBServer.globals.wwwroot) {
|
if (!min && !url.startsWith('/static') && GBServer.globals.wwwroot) {
|
||||||
path = Path.join(GBServer.globals.wwwroot, url);
|
path = Path.join(GBServer.globals.wwwroot, url);
|
||||||
}
|
}
|
||||||
if (Fs.existsSync(path)) {
|
if (Fs.existsSync(path)) {
|
||||||
if (min) {
|
if (min) {
|
||||||
let html = Fs.readFileSync(path, 'utf8');
|
let html = Fs.readFileSync(path, 'utf8');
|
||||||
html = html.replace(/\{p\}/gi, min.botId);
|
html = html.replace(/\{p\}/gi, min.botId);
|
||||||
|
html = html.replace(/\{theme\}/gi, min.instance.theme ? min.instance.theme : 'default.gbtheme');
|
||||||
html = html.replace(/\{botId\}/gi, min.botId);
|
html = html.replace(/\{botId\}/gi, min.botId);
|
||||||
html = html.replace(/\{theme\}/gi, min.instance.theme ? min.instance.theme :
|
|
||||||
'default.gbtheme');
|
|
||||||
html = html.replace(/\{title\}/gi, min.instance.title);
|
html = html.replace(/\{title\}/gi, min.instance.title);
|
||||||
res.send(html).end();
|
res.send(html).end();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue