I put my assets in public directory, and use script tag to require them in resources/views/welcome.blade.php, likes below:
<script src="{{ mix('/js/app.js') }}"></script>
In swoole server i got 404 response, but artisan serve works fine with the same code.
// swoole server
http://127.0.0.1:1215/js/app.js // got 404
// artisan serve
http://127.0.0.1:8000/js/app.js // got 200
+1 same here.
Hi @storyn26383 ,
You can add two server.options configs in swoole_http.php
'document_root' => base_path('public'),
'enable_static_handler' => true,
The request will then bypass onRequest callback to handle static resource directly. But it will expose all the files under public folder including .php files.
The better solution will be using Nginx to handle static resources, and Swoole only handle non-static requests.
But I will try to find a better way handling static files with Swoole and add this feature in the next release.
Hi @storyn26383 @shenjiayu ,
In the release v2.3.2 will process the static resource first before dispatching request. Again, using Nginx to process static files is still a better way.
Wait, there are still some problems about content-type of static files responded by swoole server. Need to find another way.
In the release v2.3.3 I force to output correct content-type for js and css static files. This is not a good solution yet, but workable at least.
Most helpful comment
Hi @storyn26383 ,
You can add two
server.optionsconfigs inswoole_http.phpThe request will then bypass
onRequestcallback to handle static resource directly. But it will expose all the files under public folder including.phpfiles.The better solution will be using Nginx to handle static resources, and Swoole only handle non-static requests.
But I will try to find a better way handling static files with Swoole and add this feature in the next release.