walkor / webman

Probably the fastest PHP web framework in the world.
https://webman.workerman.net/
MIT License
2.2k stars 215 forks source link

How to set plugin route to load before dynamic route? #407

Open leekung opened 5 months ago

leekung commented 5 months ago

I have dynamic route in config/route.php like this (it load vue + vue router)

Route::disableDefaultRoute();
Route::get('[{path:.+}]', [IndexController::class, 'index'])->name('public.index');

then I add webman/push plugin that has its own route file but got error when run

FastRoute\BadRouteException: Static route "/plugin/webman/push/push.js" is shadowed by previously defined variable route "(.+)" for method "GET" in /Users/mactat/Work/Gambling/source/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php:95
Stack trace:
#0 /Users/mactat/Work/Gambling/source/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php(30): FastRoute\DataGenerator\RegexBasedAbstract->addStaticRoute('GET', Array, Array)
#1 /Users/mactat/Work/Gambling/source/vendor/nikic/fast-route/src/RouteCollector.php(44): FastRoute\DataGenerator\RegexBasedAbstract->addRoute('GET', Array, Array)
#2 /Users/mactat/Work/Gambling/source/vendor/workerman/webman-framework/src/Route.php(382): FastRoute\RouteCollector->addRoute('GET', '/plugin/webman/...', Array)

I think if I can set the plugin route to load first it will work but dont know how to set it or any other solution to fix this

yisibugua commented 1 week ago
/**
 * 推送js客户端文件
 */
Route::get('/plugin/webman/push/push.js', function (Request $request) {
    return response()->file(base_path().'/vendor/webman/push/src/push.js');
});