Skip to content

Commit

Permalink
Serve script and configuration improved
Browse files Browse the repository at this point in the history
  • Loading branch information
oytuntez committed Feb 15, 2022
1 parent d49feac commit a2cfb51
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
9 changes: 9 additions & 0 deletions config/motaword.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
|
*/
'serve_url' => env('MOTAWORD_ACTIVE_SERVE_URL', 'https://serve.motaword.com'),
/*
|--------------------------------------------------------------------------
| Active JS URL
|--------------------------------------------------------------------------
|
| This is the base URL for front facing Active experience. This is typically used if Serve is disabled.
|
*/
'active_js_url' => env('MOTAWORD_ACTIVE_JS_URL', 'https://active-js.motaword.com/index.js'),

/*
|--------------------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions src/ActiveJS.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ public static function generate(): string
{
$config = config('motaword.active');

if (!$config || !$config['token'] || !$config['project_id'] || !$config['widget_id'] || !$config['serve_url']) {
if (!$config || !$config['project_id'] || !$config['widget_id'] || !$config['token']
|| ($config['serve_enable'] && !$config['serve_url'])
|| (!$config['serve_enable'] && !$config['active_js_url'])) {
throw new Exception('Token, project ID and widget ID are required for MotaWord Active.');
}

return "<script src=\"${config['serve_url']}/js/${config['project_id']}-${config['widget_id']}.js\" crossorigin async></script>";
if ($config['serve_enable']) {
return "<script src=\"${config['serve_url']}/js/${config['project_id']}-${config['widget_id']}.js\" ".($config['token'] ? 'data-token="'.$config['token'].'"' : '')." crossorigin async></script>";
} else {
return "<script src=\"${config['active_js_url']}\" ".($config['token'] ? 'data-token="'.$config['token'].'"' : '')." ".($config['project_id'] ? 'data-project-id="'.$config['project_id'].'"' : '')." ".($config['widget_id'] ? 'data-widget-id="'.$config['widget_id'].'"' : '')." crossorigin async></script>";
}
}
}
7 changes: 0 additions & 7 deletions src/ActiveServeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ public function handle(Request $request, Closure $next)
private function shouldShowPrerenderedPage(Request $request): bool
{
$userAgent = strtolower($request->server->get('HTTP_USER_AGENT'));
$bufferAgent = $request->server->get('X-BUFFERBOT');

$requestUri = $request->getRequestUri();
$referer = $request->headers->get('Referer');

Expand All @@ -149,10 +147,6 @@ private function shouldShowPrerenderedPage(Request $request): bool
}
}

if ($bufferAgent) {
$isRequestingPrerenderedPage = true;
}

if (!$isRequestingPrerenderedPage) {
return false;
}
Expand All @@ -178,7 +172,6 @@ private function shouldShowPrerenderedPage(Request $request): bool
}
}

// Okay! Prerender please.
return true;
}

Expand Down

0 comments on commit a2cfb51

Please sign in to comment.