Skip to content

Commit

Permalink
Overall improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyCyborg committed Jul 13, 2019
1 parent 1963dd7 commit 4616edb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function boot(Router $router)
parent::boot($router);

//
$this->loadAssetRoutes();
}

/**
Expand All @@ -49,4 +50,17 @@ public function map(Router $router)
require $path .DS .'Web.php';
});
}


/**
* Define the asset routes for the application.
*
* @return void
*/
protected function loadAssetRoutes()
{
$dispatcher = $this->app['assets.dispatcher'];

require app_path('Routes') .DS .'Assets.php';
}
}
43 changes: 43 additions & 0 deletions app/Routes/Assets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use Nova\Http\Request;
use Nova\Http\Response;


// Register the route for assets from main assets folder.
$dispatcher->route('assets/(.*)', function (Request $request, $path) use ($dispatcher)
{
$basePath = Config::get('routing.assets.path', base_path('assets'));

$path = $basePath .DS .str_replace('/', DS, $path);

return $dispatcher->serve($path, $request);
});

// Register the route for assets from Packages, Modules and Themes.
$dispatcher->route('packages/([^/]+)/([^/]+)/(.*)', function (Request $request, $vendor, $package, $path) use ($dispatcher)
{
$namespace = $vendor .'/' .$package;

if (is_null($packagePath = $dispatcher->getPackagePath($namespace))) {
return new Response('File Not Found', 404);
}

$path = $packagePath .str_replace('/', DS, $path);

return $dispatcher->serve($path, $request);
});

// Register the route for assets from Vendor.
$dispatcher->route('vendor/(.*)', function (Request $request, $path) use ($dispatcher)
{
$paths = $dispatcher->getVendorPaths();

if (! Str::startsWith($path, $paths)) {
return new Response('File Not Found', 404);
}

$path = BASEPATH .'vendor' .DS .str_replace('/', DS, $path);

return $dispatcher->serve($path, $request);
});

0 comments on commit 4616edb

Please sign in to comment.