Skip to content

Commit

Permalink
Feat: Add Coming Soon page with redirects enforced via Pennant + midd…
Browse files Browse the repository at this point in the history
…leware
  • Loading branch information
nikspyratos committed Mar 27, 2024
1 parent 3965240 commit ca4aeb7
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ DEPLOYMENT_IP=
DEPLOYMENT_USER=ubuntu
DEPLOYMENT_SSH_KEY=
DEPLOYMENT_PATH=

COMING_SOON_ENABLED=false
2 changes: 1 addition & 1 deletion .env.prod.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ VITE_REVERB_SCHEME="${REVERB_SCHEME}"
OCTANE_HTTPS=true
OCTANE_SERVER=frankenphp


COMING_SOON_ENABLED=false
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ These are the next steps you will have to implement yourself for your project as
- For some projects you probably won't even need the landing page provided, so go ahead and yank it out!
- **License**: If your project is closed-source, you might want to remove the `LICENSE.md` file included in the repo.
- **Social Logins**: For each provider you plan on adding, you'll need to add the relevant credentials and configuration for both [Socialite](https://laravel.com/docs/11.x/socialite#configuration) and [Socialstream](https://docs.socialstream.dev/getting-started/configuration#providers). If you'd like to add additional social login providers, please check out the [Socialite Providers](https://socialiteproviders.com/) site.
- **Feature flags**: By default the `array` driver is used for Pennant feature flags. If you'd like to use the `database` driver instead, make sure to [publish the migrations](https://laravel.com/docs/11.x/pennant#installation) and change the `PENNANT_STORE` environment variable.
- **Coming Soon**: To redirect public routes to a "Coming Soon" page before launch, change the `COMING_SOON_ENABLED` environment variable and re-cache your config. This feature is implemented using Pennant for an example implementation. You can delete the middleware, feature definition, and environment variable post-launch.

#### Ongoing Development

Expand Down Expand Up @@ -556,6 +558,10 @@ While you're solo, I'd recommend one of the following:

Once you need to start having the knowledgebase available to others, [Notion](https://notion.so) is my go-to. Notion also supports making public pages, so you can also have your customer knowledgebase there.

### Roadmap Management

[Suggest.gg](https://suggest.gg/)

### Accounting

I don't know too much in this space other than [Xero](https://www.xero.com).
Expand Down Expand Up @@ -592,6 +598,7 @@ These are some features that would be nice to have, but I don't intend on buildi
- Blog RSS feed
- Confirmed working Windows environment solution: I don't work on Windows, and while Herd may be a first prize solution, I do want a free setup recommendation to have for Windows devs.
- Let me know if any new file changes need to be added to the Jetstream Teams installer.
- Convert some of the install scripts to be Prompts-based (or hybrid with Prompts)

---

Expand Down
31 changes: 31 additions & 0 deletions app/Http/Middleware/ComingSoon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Laravel\Pennant\Feature;
use Symfony\Component\HttpFoundation\Response;

class ComingSoon
{
/**
* Handle an incoming request.
*
* @param Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Feature::active('coming-soon') && $request->route()->getName() !== 'coming-soon') {
return redirect(route('coming-soon'));
}

if (Feature::inactive('coming-soon') && $request->route()->getName() === 'coming-soon') {
return redirect(route('home'));
}

return $next($request);
}
}
2 changes: 2 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
//teams_use_placeholder
use Laravel\Pennant\Concerns\HasFeatures;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
Expand All @@ -26,6 +27,7 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
use HasApiTokens;
use HasConnectedAccounts;
use HasFactory;
use HasFeatures;
use HasProfilePhoto {
HasProfilePhoto::profilePhotoUrl as getPhotoUrl;
}
Expand Down
3 changes: 3 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Laravel\Pennant\Feature;

class AppServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -43,6 +44,8 @@ public function boot(): void
$this->app->register(TelescopeServiceProvider::class);
}

Feature::define('coming-soon', static fn (?User $user) => ! $user?->is_admin && config('app.coming_soon_enabled'));

$this->bootAuth();
$this->bootEvent();
$this->bootRoute();
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/FolioServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Providers;

use App\Http\Middleware\ComingSoon;
use Illuminate\Support\ServiceProvider;
use Laravel\Folio\Folio;

Expand All @@ -25,7 +26,7 @@ public function boot(): void
->uri('/')
->middleware([
'*' => [
// Add yours here...
ComingSoon::class,
],
]);
}
Expand Down
5 changes: 5 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use App\Http\Middleware\ComingSoon;
use App\Providers\AppServiceProvider;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
Expand All @@ -21,6 +22,10 @@
$middleware->redirectUsersTo(AppServiceProvider::HOME);

$middleware->throttleApi();

$middleware->appendToGroup('web', [
ComingSoon::class
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
Expand Down
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,6 @@

'default_description' => 'A TALL stack starter kit for solopreneurs',

'coming_soon_enabled' => env('COMING_SOON_ENABLED', false),

];
2 changes: 1 addition & 1 deletion resources/views/layouts/marketing.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@livewireStyles
</head>
<body>
@include('layouts.marketing.navigation')
@include('layouts.marketing.navigation', ['includeNav' => $includeNav ?? true])
<main>
@yield('content')
</main>
Expand Down
2 changes: 2 additions & 0 deletions resources/views/layouts/marketing/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<img src="{{ asset('images/toybox-logo.png') }}" class="mr-3 h-6 sm:h-9" alt="Toybox Logo" />
<span class="self-center text-xl font-semibold whitespace-nowrap dark:text-matisse-400">{{ config('app.name') }}</span>
</a>
@if($includeNav)
<div class="flex items-center lg:order-2">
@if (Route::has('login'))
@auth
Expand Down Expand Up @@ -44,6 +45,7 @@
@endforeach
</ul>
</div>
@endif
</div>
</nav>
</header>
27 changes: 27 additions & 0 deletions resources/views/pages/coming-soon.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
use function Laravel\Folio\name;
name('coming-soon');
?>

@extends('layouts.marketing', ['includeNav' => false])

@section('pageTitle')
{{ config('app.name') . ' is coming soon!' }}
@endsection

@section('content')
<section class="primary-section">
<div class="grid px-4 pb-8 mx-auto max-w-screen-xl lg:grid-cols-12 lg:gap-8 lg:pb-16 xl:gap-0">
<div class="place-self-center mr-auto lg:col-span-7">
<h1>Coming soon!</h1>
<p class="headline">Something interesting this way comes...</p>
</div>
<div class="lg:flex lg:col-span-5 lg:mt-0">
Hero Image here
</div>
</div>
</section>
@endsection

0 comments on commit ca4aeb7

Please sign in to comment.