Skip to content

Commit

Permalink
fix(all): Minor changes in PROD.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jul 28, 2023
1 parent fda66b8 commit 245e491
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .hintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"development"
],
"hints": {
"typescript-config/strict": "off"
"typescript-config/strict": "off",
"typescript-config/consistent-casing": "off"
}
}
33 changes: 21 additions & 12 deletions packages/core.gbapp/services/GBSSR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ export class GBSSR {
};
}


public static async createBrowser(profilePath): Promise<any> {
const opts = this.preparePuppeteer(profilePath);
puppeteer.use(hidden());
puppeteer.use(require('puppeteer-extra-plugin-minmax')());
puppeteer.use(require("puppeteer-extra-plugin-minmax")());
const browser = await puppeteer.launch(opts);
return browser;
}
Expand Down Expand Up @@ -284,26 +285,31 @@ export class GBSSR {

const minBoot = GBServer.globals.minBoot;

const onlyChars = /\/([A-Za-z0-9\-\_]+)\/*/.exec(req.originalUrl);
let onlyChars:any = /\/([A-Za-z0-9\-\_]+)\/*/.exec(req.originalUrl);
onlyChars = onlyChars? onlyChars[1]: null;

let botId =
req.originalUrl && req.originalUrl === '/' ?
minBoot.botId :
onlyChars;

let botId = (req.originalUrl && req.originalUrl === '/') || onlyChars ? onlyChars[1] : minBoot.botId;

let min: GBMinInstance =
req.url === '/'
? minBoot
: GBServer.globals.minInstances.filter(p => p.instance.botId.toLowerCase() === botId.toLowerCase())[0];
if (!min) {
min =
req.url === '/'
? minBoot
: GBServer.globals.minInstances.filter(p =>
p.instance.activationCode ? p.instance.activationCode.toLowerCase() === botId.toLowerCase() : null
)[0];
min = req.url === '/'
? minBoot
: GBServer.globals.minInstances.filter(p =>
p.instance.activationCode ? p.instance.activationCode.toLowerCase() === botId.toLowerCase()
: null)[0];
}
if (!min) {
botId = minBoot.botId;
}


let path = DialogKeywords.getGBAIPath(botId, `gbui`);

// Checks if the bot has an .gbui published or use default.gbui.
Expand All @@ -315,13 +321,15 @@ export class GBSSR {
let url = parts[0];

if (min && req.originalUrl && prerender && exclude) {

// Reads from static HTML when a bot is crawling.

path = Path.join(process.env.PWD, 'work', path, 'index.html');
const html = Fs.readFileSync(path, 'utf8');
res.status(200).send(html);
return true;
} else {

// Servers default.gbui web application.

path = Path.join(
Expand All @@ -332,17 +340,18 @@ export class GBSSR {
url === '/' || url === '' ? `index.html` : 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);
}
if (Fs.existsSync(path)) {
if (min) {
let html = Fs.readFileSync(path, 'utf8');
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(/\{theme\}/gi, min.instance.theme ? min.instance.theme :
'default.gbtheme');
html = html.replace(/\{title\}/gi, min.instance.title);
res.send(html).end();
} else {
Expand Down

0 comments on commit 245e491

Please sign in to comment.