Skip to content

Instantly share code, notes, and snippets.

@1isten
Last active January 22, 2024 11:36
Show Gist options
  • Select an option

  • Save 1isten/2b65ebc66d9486d03940a5dce873bccc to your computer and use it in GitHub Desktop.

Select an option

Save 1isten/2b65ebc66d9486d03940a5dce873bccc to your computer and use it in GitHub Desktop.

Revisions

  1. 1isten revised this gist Jan 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion web.php
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    // ...

    Route::fallback(function () {
    $static = 'static';
    $static = 'static'; // static folder in project root
    $static_file = request()->path() === '/' ? base_path($static) : implode(DIRECTORY_SEPARATOR, array_merge(array(base_path($static)), explode('/', request()->path())));
    if (is_dir($static_file)) {
    $static_file = implode(DIRECTORY_SEPARATOR, array($static_file, 'index.html'));
  2. 1isten revised this gist Jan 22, 2024. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions web.php
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,14 @@
    $static_file = implode(DIRECTORY_SEPARATOR, array($static_file, 'index.html'));
    }
    if (file_exists($static_file)) {
    return response()->file($static_file, ['Content-Type' => \GuzzleHttp\Psr7\MimeType::fromFilename($static_file)]);
    $mimeType = \GuzzleHttp\Psr7\MimeType::fromFilename($static_file);
    return response()->file($static_file, [
    // 'Cache-Control' => 'public,max-age=0,must-revalidate',
    'Content-Type' => $mimeType ? $mimeType : 'application/octet-stream',
    ]);
    }
    return response(['error' => 404, 'message' => '404 Not Found'], 404);
    return response([
    'error' => 404,
    'message' => '404 Not Found',
    ], 404);
    });
  3. 1isten revised this gist Jan 22, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions web.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    // Route::get('/', ...

    // ...
  4. 1isten created this gist Jan 22, 2024.
    15 changes: 15 additions & 0 deletions web.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // Route::get('/', ...

    // ...

    Route::fallback(function () {
    $static = 'static';
    $static_file = request()->path() === '/' ? base_path($static) : implode(DIRECTORY_SEPARATOR, array_merge(array(base_path($static)), explode('/', request()->path())));
    if (is_dir($static_file)) {
    $static_file = implode(DIRECTORY_SEPARATOR, array($static_file, 'index.html'));
    }
    if (file_exists($static_file)) {
    return response()->file($static_file, ['Content-Type' => \GuzzleHttp\Psr7\MimeType::fromFilename($static_file)]);
    }
    return response(['error' => 404, 'message' => '404 Not Found'], 404);
    });