Skip to content

Commit acdbd70

Browse files
committed
Serve feeds via PHP
To get around nginx config.
1 parent af9ab19 commit acdbd70

4 files changed

Lines changed: 16 additions & 9 deletions

File tree

app/Console/Commands/GenerateFeeds.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ private function writeFeed(string $fileName, string $id, string $title, string $
8787
])->render();
8888

8989
$fs = new Filesystem;
90-
$fs->put(public_path('feeds/'.$fileName), $contents);
90+
$fs->put(storage_path('feeds/'.$fileName), $contents);
9191
}
9292
}

app/Http/Controllers/Feeds/Show.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
namespace App\Http\Controllers\Feeds;
44

5+
use Illuminate\Contracts\Filesystem\FileNotFoundException;
6+
use Illuminate\Filesystem\Filesystem;
7+
58
class Show
69
{
7-
public function __invoke()
10+
public function __invoke(string $feed, Filesystem $filesystem): string
811
{
9-
// 1. Every hour, a command should be fired to (re)generate the feeds.
10-
// 2. This command creates static files that are served directly by NGINX.
12+
try {
13+
return $filesystem->get(storage_path("feeds/{$feed}.xml"));
14+
} catch (FileNotFoundException $e) {
15+
abort(404);
16+
}
1117
}
1218
}

routes/web.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
Route::get('/explore', Explore::class)->name('explore');
1515

1616
Route::get('/feeds', Feeds\Index::class)->name('feeds.index');
17+
Route::get('/feeds/{feed}.xml', Feeds\Show::class)->name('feeds.show');
1718

18-
Route::get('articles', Articles\Index::class)->name('articles.index');
19-
Route::get('articles/{article}', Articles\Show::class)->name('articles.show');
20-
Route::get('posts/{article}', Articles\Show::class)->name('posts.show');
19+
Route::get('/articles', Articles\Index::class)->name('articles.index');
20+
Route::get('/articles/{article}', Articles\Show::class)->name('articles.show');
21+
Route::get('/posts/{article}', Articles\Show::class)->name('posts.show');
2122

22-
Route::get('concerts', Concerts\Index::class)->name('concerts.index');
23-
Route::get('concerts/{date}/{concert}', Concerts\Show::class)->name('concerts.show');
23+
Route::get('/concerts', Concerts\Index::class)->name('concerts.index');
24+
Route::get('/concerts/{date}/{concert}', Concerts\Show::class)->name('concerts.show');
2425

2526
Route::get('/archive', Archive::class)->name('archive');

0 commit comments

Comments
 (0)