Laravel-swoole: Can't load assets via `php artisan swoole:http start`, but `php artisan serve` works fine.

Created on 5 May 2018  ·  5Comments  ·  Source: swooletw/laravel-swoole

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
enhancement question

Most helpful comment

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.

All 5 comments

+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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adon988 picture adon988  ·  5Comments

benpoulson picture benpoulson  ·  3Comments

junshenshi picture junshenshi  ·  3Comments

MikeMaldini picture MikeMaldini  ·  10Comments

aftabnaveed picture aftabnaveed  ·  4Comments