KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Koolreport_assets error #3170

Closed afieq opened this topic on on Oct 16, 2023 - 4 comments

afieq commented on Oct 16, 2023

Hi,

I encounter a problem where i have push my codes into my server for everyone to access and test. I don't have this problem on my local pc, but when i upload my koolreport codes encounter error on url path that is /koolreport_assets/3949676905/KoolReport.js but on my local it's only using the /koolreport/core/src/clients/core/KoolReport.js. It's seems it using the newly created file koolreport_assets on my server but on my local only using the koolreport/core. Where does this files comes from and why its created on my server and not on my local?

May i know on how can i solve this error on my server? Thank you in advance.

Regards, Afieq

Sebastian Morales commented on Oct 16, 2023

Like most web frameworks, KoolReport needs help of css, js client files. KoolReport.js is one of the client files.

On your localhost machine, the local web server normally allows client access of the https://localhost/{path to}/koolreport/core/src/clients/core/KoolReport.js file.

But on your server, it's most likely that the production web server doesn't allow direct access of client files inside PHP packages installed in vendor directory for security reasons. In this case, KoolReport needs to copy its client files to a koolreport_assets subdirectory inside a public directory for user browsers to be able to load them.

For KoolReport to know where to place koolreport_assets subdirectory in, you would need to set a report's assets setting as described here:

https://www.koolreport.com/docs/architecture/assets_settings/

class MyReport extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            ...
            "assets"=>array(
                "path"=>"../../public_dir/koolreport_assets", //file path to the public directory's koolreport_assets sub dir
                "url"=>"/public_dir/koolreport_assets", //url to the public directory's koolreport_assets sub dir
            )
        );
    }
}

Or if you Laravel you can use the following Laravel friendship trait instead:

https://www.koolreport.com/docs/laravel/overview/

class MyReport extends \koolreport\KoolReport
{
    use \koolreport\laravel\Friendship;
    // By adding above statement, you have claim the friendship between two frameworks
    // As a result, this report will be able to accessed all databases of Laravel
    // There are no need to define the settings() function anymore
    // while you can do so if you have other datasources rather than those
    // defined in Laravel.
afieq commented on Oct 17, 2023

Hi Sebastian,

For my case, my code is using koolreport dashboard. So where do i put the setting that you have mention. My error shows 'Failed to load resource: the server responded with a status of 404 (Not Found) and "Uncaught ReferenceError: KoolReport is not defined", but i already have the koolreport file package in my file directory?

I also tried a simple report SalesByCountry, it works on my local. But when i push to my server it does not work, the web shows error "HTTP ERROR 500". My server is using linux while my local is using windows. Is there solution for my problem?

Thanks in advance.

Regards, Afieq

Sebastian Morales commented on Oct 17, 2023

In case you use KoolReport Dashboard on a production Linux server, you can set its assets in App's setTheme() function like this:

//dashboard-demo/App.php
class App extends \koolreport\dashboard\Application
{
    protected function setTheme($name)
    {
        switch ($name) {
            case "Amazing":
                $this->theme(Amazing::create()
                    ->assets([
                        "path" => "./public", // change this to your dashboard project's public dir file path
                        "url" => "/url/path/to/dashboard-demo/public", // change this to your dashboard project's public dir url
                    ])
                );
                break;
            case "AppStack":
                $this->theme(AppStack::create()
                    ->assets([
                        "path" => "./public", // change this to your dashboard project's public dir file path
                        "url" => "/url/path/to/dashboard-demo/public", // change this to your dashboard project's public dir url
                    ])
                );
                break;
        }
    } 

Remember to create a directory called "public" somewhere in your dashboard project and config your web server for client browsers to be able to access css and js files in that public dir.

afieq commented on Oct 18, 2023

Hi Sebastian,

Based on the guidance you given, finally i can resolve the error i encounter on my server. The solution is on the App.php file, i added this two function based on the file in my directory then it works like a charm. After adding the function assets, i found that i also have to manually set the theme for my dashboard to work because its not calling the default theme setting. Thanks for your help on solving my issue, here also i attach the link that help me solving my problem.

https://www.koolreport.com/docs/dashboard/theme/

protected function onCreated()
    {
        $this->theme(
            Amazing::create()
                ->assets([
                    "path"=>"../koolreport/dashboard/assets",     //Path that js or css will be exported to
                    "url"=>"../koolreport/dashboard/assets",        //Url that those exported js and css can be accessed via browser
                ])
        );
    }

https://www.koolreport.com/docs/dashboard/application/

protected function assets()
    {
        return [
            "url"=>"../../koolreport_assets",
            "path"=>"../../koolreport_assets"
        ];
    }

Thanks and Regards, Afieq

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None