Skip to content

Commit

Permalink
feat: SSR support (#303)
Browse files Browse the repository at this point in the history
* init ssr support

* wip

* wip

* add SSR support to the Dockerfile

* replace Vue3PictureSwipe component
  • Loading branch information
andreiio committed Nov 8, 2023
1 parent f15aa55 commit 0602bba
Show file tree
Hide file tree
Showing 79 changed files with 1,407 additions and 1,331 deletions.
32 changes: 32 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/.git
/.github
/.husky
/.idea
/.vscode
/bootstrap/cache/*.php
/coverage
/node_modules
/public/assets
/public/hot
/public/storage
/public/vendor
/storage/*.key
/storage/app/*
/storage/clockwork
/storage/debugbar
/storage/framework/cache/data/*
/storage/framework/sessions/*
/storage/framework/testing/*
/storage/framework/views/*
/storage/logs/*
/vendor
_ide_helper_models.php
_ide_helper.php
.DS_Store
.env
.php_cs.cache
.php-cs-fixer.cache
.phpstorm.meta.php
.phpunit.result.cache
docker-compose.yml
Dockerfile
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-fpm-alpine as vendor
FROM php:8.1-fpm-alpine AS vendor

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp
Expand Down Expand Up @@ -33,7 +33,7 @@ RUN composer install \
--no-dev \
--prefer-dist

FROM node:18-alpine as assets
FROM node:20-alpine AS assets

WORKDIR /build

Expand All @@ -52,7 +52,7 @@ RUN npm run build

FROM vendor

ARG S6_OVERLAY_VERSION=3.1.2.1
ARG S6_OVERLAY_VERSION=3.1.6.0

ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
Expand All @@ -67,6 +67,12 @@ COPY docker/php/www.conf /usr/local/etc/php-fpm.d/zz-docker.conf
COPY docker/s6-rc.d /etc/s6-overlay/s6-rc.d

COPY --from=assets --chown=www-data:www-data /build/public/build /var/www/public/build
COPY --from=assets /build/node_modules /var/www/node_modules
COPY --from=assets /usr/lib /usr/lib
COPY --from=assets /usr/local/share /usr/local/share
COPY --from=assets /usr/local/lib /usr/local/lib
COPY --from=assets /usr/local/include /usr/local/include
COPY --from=assets /usr/local/bin /usr/local/bin

ENV APP_ENV production
ENV APP_DEBUG false
Expand Down
46 changes: 35 additions & 11 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Http\Request;
use Inertia\Middleware;
use Tightenco\Ziggy\Ziggy;

class HandleInertiaRequests extends Middleware
{
Expand All @@ -23,17 +24,40 @@ class HandleInertiaRequests extends Middleware
*/
public function share(Request $request): array
{
return array_merge(parent::share($request), [
'flash' => fn () => $this->flash($request),
'auth' => [
'user' => $request->user(),
],
'organization_status' => fn () => $request->user()?->organization?->status,
'locales' => fn () => [
'available' => locales(),
'current' => app()->getLocale(),
],
]);
return array_merge(
parent::share($request),
$this->shareOnce($request),
[
'appName' => config('app.name'),
'flash' => fn () => $this->flash($request),
'auth' => fn () => [
'user' => $request->user(),
'organization' => [
'status' => $request->user()?->organization?->status,
],
],
'locales' => [
'available' => locales(),
'current' => app()->getLocale(),
],
]
);
}

/**
* Define the props that are shared on first load only.
*
* @return array<string, mixed>
*/
public function shareOnce(Request $request): array
{
if ($request->inertia()) {
return [];
}

return [
'ziggy' => new Ziggy,
];
}

protected function flash(Request $request): ?array
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"spatie/laravel-newsletter": "^5.1",
"spatie/laravel-query-builder": "^5.3",
"stevegrunwell/time-constants": "^1.1",
"tightenco/ziggy": "^1.6"
"tightenco/ziggy": "^1.8"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.9",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions config/ziggy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

return [

'skip-route-function' => true,

'except' => [
'debugbar.*',
'dusk.*',
'filament.*',
'horizon.*',
'ignition.*',
'telescope',
],

];
5 changes: 5 additions & 0 deletions docker/s6-rc.d/ssr/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/command/with-contenv sh

cd /var/www

php artisan inertia:start-ssr
1 change: 1 addition & 0 deletions docker/s6-rc.d/ssr/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Loading

0 comments on commit 0602bba

Please sign in to comment.