-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d55ea83
Showing
11 changed files
with
483 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Ignore all test and documentation with "export-ignore". | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.github export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/tests export-ignore | ||
/docs export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/vendor | ||
/storage/framework/testing | ||
.env | ||
.phpunit.result.cache | ||
npm-debug.log | ||
yarn-error.log | ||
composer.lock | ||
bootstrap/cache/packages.php | ||
bootstrap/cache/services.php | ||
|
||
docs/*.blade.php | ||
docs/**/*.blade.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
preset: laravel | ||
|
||
disabled: | ||
- concat_without_spaces | ||
- not_operator_with_successor_space | ||
- cast_spaces | ||
- trailing_comma_in_multiline_array | ||
- heredoc_to_nowdoc | ||
- phpdoc_summary | ||
|
||
risky: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Changelog | ||
## Unreleased | ||
|
||
## v0.0.1 - January 7th, 2022 | ||
|
||
First release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Hammerstone | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
# Sidecar SSR for InertiaJS | ||
|
||
> 🚨 This is currently very much in beta! | ||
## Overview | ||
|
||
This package provides a Sidecar function to run [Inertia server-side rendering](https://inertiajs.com/server-side-rendering) on AWS Lambda. | ||
|
||
Sidecar packages, deploys, and executes AWS Lambda functions from your Laravel application. | ||
|
||
It works with any Laravel 7 or 8 application, hosted anywhere including your local machine, Vapor, Heroku, a shared virtual server, or any other kind of hosting environment. | ||
|
||
- [Sidecar docs](https://hammerstone.dev/sidecar/docs/main/overview) | ||
- [Sidecar GitHub](https://github.com/hammerstonedev/sidecar) | ||
|
||
You can see a fully working Jetstream + Inertia + Sidecar demo app at hammerstone/TODO | ||
|
||
## Enabling SSR | ||
|
||
Following the [official Inertia docs](https://inertiajs.com/server-side-rendering#enabling-ssr) on enabling SSR is a good place to start, but there are a few things you can skip: | ||
|
||
- You do not need to `npm install @inertiajs/server` | ||
- You do not need to `npm install webpack-node-externals` | ||
- Come back here when you get to the "Building your application" section | ||
|
||
### Updating Inertia | ||
|
||
Make sure that `inertia/laravel-inertia` is at least version `0.5.1`. | ||
|
||
### Installation | ||
|
||
To require this package, run the following: | ||
|
||
```shell | ||
composer require hammerstone/sidecar-inertia | ||
``` | ||
|
||
This will install Sidecar as well. | ||
|
||
### Use the Sidecar Gateway | ||
|
||
Update your `AppServiceProvider` to use the `SidecarGateway` as the default Inertia SSR Gateway | ||
|
||
```php | ||
namespace App\Providers; | ||
|
||
use Hammerstone\Sidecar\Inertia\SidecarGateway; | ||
use Illuminate\Support\ServiceProvider; | ||
use Inertia\Ssr\Gateway; | ||
|
||
class AppServiceProvider extends ServiceProvider | ||
{ | ||
public function register() | ||
{ | ||
// Use Sidecar to run Inertia SSR. | ||
$this->app->instance(Gateway::class, new SidecarGateway); | ||
} | ||
} | ||
``` | ||
|
||
### Update Configuration | ||
|
||
Update your `config/inertia.php` to include the Sidecar settings | ||
|
||
```php | ||
<?php | ||
|
||
return [ | ||
'ssr' => [ | ||
'enabled' => true, | ||
|
||
'sidecar' => [ | ||
// The Sidecar function that handles the SSR. | ||
'handler' => \Hammerstone\Sidecar\Inertia\SSR::class, | ||
|
||
// Log some stats on how long each Lambda request takes. | ||
'timings' => false, | ||
|
||
// Throw exceptions, should they occur. | ||
'debug' => env('APP_DEBUG', false), | ||
], | ||
], | ||
|
||
// ... | ||
]; | ||
``` | ||
|
||
### Configure Sidecar | ||
|
||
If you haven't already, you'll need to configure Sidecar. | ||
|
||
Publish the `sidecar.php` configuration file by running | ||
|
||
```shell | ||
php artisan sidecar:install | ||
``` | ||
|
||
To configure your Sidecar AWS credentials interactively, you can run | ||
|
||
```shell | ||
php artisan sidecar:configure | ||
``` | ||
|
||
The [official Sidecar docs](https://hammerstone.dev/sidecar/docs/main/configuration) go into much further detail. | ||
|
||
Now update your `config/sidecar.php` to include the function shipped with this package. | ||
|
||
```php | ||
<?php | ||
|
||
return [ | ||
'functions' => [ | ||
\Hammerstone\Sidecar\Inertia\SSR::class | ||
], | ||
|
||
// ... | ||
]; | ||
``` | ||
|
||
### Updating Your JavaScript | ||
|
||
> This only covers Vue3, please follow the Inertia docs for Vue2 or React, and please open any issues. | ||
You'll need to update your `webpack.ssr.mix.js` file. This _should_ work for most cases, but please open any issues for errors you run into. (This is based on the Inertia docs, with slight modifications.) | ||
|
||
```js | ||
const path = require('path') | ||
const mix = require('laravel-mix') | ||
|
||
mix | ||
.js('resources/js/ssr.js', 'public/js') | ||
.options({ | ||
manifest: false | ||
}) | ||
.vue({ | ||
version: 3, | ||
useVueStyleLoader: true, | ||
options: { | ||
optimizeSSR: true | ||
} | ||
}) | ||
.alias({ | ||
'@': path.resolve('resources/js') | ||
}) | ||
.webpackConfig({ | ||
target: 'node', | ||
externals: { | ||
node: true, | ||
}, | ||
resolve: { | ||
alias: { | ||
// Uncomment if you're using Ziggy. | ||
// ziggy: path.resolve('vendor/tightenco/ziggy/src/js'), | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
And update your `resources/js/ssr.js` to look something like this. The specifics may vary based on your application. If you're using [Ziggy](https://github.com/tighten/ziggy), you'll want to uncomment the Ziggy stuff. (This is based on the Inertia docs, with slight modifications.) | ||
|
||
```js | ||
import {createSSRApp, h} from 'vue' | ||
import {renderToString} from '@vue/server-renderer' | ||
import {createInertiaApp} from '@inertiajs/inertia-vue3' | ||
// import route from 'ziggy'; | ||
|
||
// This is the Lambda handler that will respond to the Sidecar invocation. | ||
exports.handler = async function (event) { | ||
return await createInertiaApp({ | ||
page: event, | ||
render: renderToString, | ||
resolve: (name) => require(`./Pages/${name}`), | ||
setup({app, props, plugin}) { | ||
// const Ziggy = { | ||
// ...event.props.ziggy, | ||
// location: new URL(event.props.ziggy.url) | ||
// } | ||
|
||
return createSSRApp({ | ||
render: () => h(app, props), | ||
}).use(plugin).mixin({ | ||
methods: { | ||
// Pull the ziggy config off of the event. | ||
// route: (name, params, absolute, config = Ziggy) => route(name, params, absolute, config), | ||
}, | ||
}) | ||
}, | ||
}); | ||
} | ||
``` | ||
|
||
### Ziggy (Optional) | ||
|
||
If you are using Ziggy, you'll need to pass the Ziggy information along to your Lambda. You can do that by adding the following to your | ||
`HandleInertiaRequests` middleware. | ||
|
||
```php | ||
class HandleInertiaRequests extends Middleware | ||
{ | ||
public function share(Request $request) | ||
{ | ||
return array_merge(parent::share($request), [ | ||
'ziggy' => (new Ziggy)->toArray() | ||
]); | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "hammerstone/sidecar-inertia", | ||
"description": "A Laravel package to render Inertia apps on AWS Lambda.", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Aaron Francis", | ||
"email": "aaron@hammerstone.dev" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.2|^8.0", | ||
"hammerstone/sidecar": "v0.3.4", | ||
"inertiajs/inertia-laravel": "^0.5.1", | ||
"illuminate/support": "^8.0" | ||
}, | ||
"require-dev": { | ||
"orchestra/testbench": "^5.0|^6.0", | ||
"mockery/mockery": "^1.3.3", | ||
"phpunit/phpunit": "^8.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Hammerstone\\Sidecar\\Inertia\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Hammerstone\\Sidecar\\Inertia\\Tests\\": "tests/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
<testsuite name="integration"> | ||
<directory>tests/Integration</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<php> | ||
</php> | ||
</phpunit> |
Oops, something went wrong.