Inertia-Echo - An Echo Server-Side Adapter for Inertia.js

Inertia-Echo is an Echo (Go) server-side adapter for Inertia.js to build modern monolithic single-page apps. Based on inertia-laravel and zgabievi's PingCRM Demo.

A demo app can be found in the demo branch at https://github.com/elipZis/inertia-echo/tree/demo

Pre-requisites

Download and install Golang for your platform.

Notes

This module serves as middleware to the Echo server system and has to be registered accordingly. It is not intended to be used without Echo and a client-side Inertia.js.

For usage instructions about Echo please refer to the official documentation

Setup

Create a copy of the example environment variables

cp .env.example .env

Setup your own properties accordingly.

In the configured resources directory you need to create a views folder and a configured INERTIA_ROOT_VIEW file. You may use the example file provided in this repository which requires Webpack and Mix.

Usage

Create a new Echo instance and register the Inertia middleware with it

import (
    ...

    "github.com/elipzis/inertia-echo"
    
    ...
)

e := echo.New()
e.Use(inertia.Middleware(e))

Import the module into your project.

The middleware hooks into the Echo error and template rendering with a dedicated Inertia instance by itself. Therefore, to render a client-side Inertia.js view you can register a route and render a component

// Handler
func hello(c echo.Context) error {
    // Status, Component Name, Data to pass on
    return c.Render(http.StatusOK, "Index", map[string]interface{}{})
}

// Route
e.GET("/hello", hello)

The internal template renderer of Inertia-Echo checks whether a fresh full base-site has to be returned or only the reduced Inertia response.

For more examples refer to the demo branch at https://github.com/elipZis/inertia-echo/tree/demo

Configuration

You can leverage several ...WithConfig functions to configure this module to your needs.

For example, you may create your own Inertia-Echo instance via NewInertia(...) and pass the instance to the middleware via

e.Use(inertia.MiddlewareWithConfig(inertia.MiddlewareConfig{
    Inertia: MyInertia,
}))

By that you enable yourself to use functionality such as Share(...) in your own e.g. handlers.

License and Credits

This module is released under the MIT license by elipZis.

This program uses multiple other libraries. Credits and thanks to all the developers working on these great projects:

and many more.

Disclaimer

This source and the whole package comes without a warranty. It may or may not harm your computer. It is not a reference for best-practices or security concerns or any other application concept. Please use with care and not as absolute reference.
Any damage cannot be related back to the author.

Top categories

svelte logo

Want a Svelte site built?

Hire a Svelte developer
Loading Svelte Themes