GithubHelp home page GithubHelp logo

dmitrymomot / inertia-echo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elipzis/inertia-echo

0.0 1.0 0.0 970 KB

๐Ÿ’ป Echo (Go) Server-Side Adapter for Inertia.js

Home Page: https://inertia-echo.herokuapp.com

License: MIT License

Shell 0.53% Go 97.00% HTML 2.48%

inertia-echo's Introduction

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

GitHub license GitHub (pre-)release Donate

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.

inertia-echo's People

Contributors

brentchesny avatar nea avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.