An open API service indexing awesome lists of open source software.

https://github.com/hemerajs/momos

Reverse proxy to define server-side-includes with HTML5 and attributes.
https://github.com/hemerajs/momos

cache distributed-systems golang reverse-proxy ssi

Last synced: 15 days ago
JSON representation

Reverse proxy to define server-side-includes with HTML5 and attributes.

Awesome Lists containing this project

README

        


Momos logo


[![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](http://opensource.org/licenses/MIT)
[![Build Status](https://travis-ci.org/hemerajs/momos.svg?branch=master)](http://travis-ci.org/hemerajs/momos)

Momos - Reverse proxy to define server-side-includes with HTML5 and attributes. No html comments or complicated configurations. **This is a proof-of-concept.**

- **Cache:** Requests are cached with RFC7234.
- **Fast:** SSI Fragments are loaded in parallel.
- **No proxy configs**: Everything is configurable via HTML5 attributes.
- **Dev-friendly**: Frontend developer can create fragments easily.
- **Fallback**: Define default content or an error template with ``.
- **Reliable**: Define a timeout message with ``.
- **Just HTML**: Define SSI fragments with pure HTML ``.
- **Templating**: Use Go Templates inside fragments and ssi tags.
- **Operational**: Easy to start and maintain. Single binary.

## Why you don't use Nginx?
Good point. Nginx is a great proxy and although it already provides robust SSI directives I would like to see a solution which doesn't require a restart or reload of the proxy when parameters has to be changed. The transition between defining SSI fragments and configure them should be smooth for any kind of developer. Momos should provide a proxy with advanced SSI functionality. Any developer should be able to place and configure SSI fragments with html knowledge.

Momos is compiled to a single binary. It provides great debugging experience to understand how your page is build which is often difficult in proxys like Nginx or Apache.

## What are SSI?

> SSI (Server Side Includes) are directives that are placed in HTML pages, and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program, or other dynamic technology.
[Reference](https://httpd.apache.org/docs/current/howto/ssi.html#page-header)

### Advantages

- Easy integration of html fragments from external services
- Share all layout html fragments to keep them [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)
- Insert fragments in pages which are usually static (e.g landing)
- In highly distributed environments it can be an advantage to integrate services on data content

## Example
```html


Default content!



Please try it again! {{.DateLocal}}




Please call the support!


```

- `name` : The name of the fragment (default `unique-id`)
- `timeout` : The maximum request timeout (default `2000`)
- `no-scripts`: Filter javascript and css includes from the fragment (default `true`)
- `src` : The url of the server-side-include
- `template` : Enables template rendering via go templates (default `false`)

## Run it

```
$ go test
$ go run examples/server.go
$ go run examples/client.go
```
### Expected output
Requests are cached for 10 seconds `max-age=10`
```
__ ___
/ |/ /__ __ _ ___ ___
/ /|_/ / _ \/ ' \/ _ \(_-<
/_/ /_/\___/_/_/_/\___/___/ 1.0.0
High performance, reverse proxy for advanced SSI
2017/08/22 20:10:48.367828 [INF] Fragment "basket3" was cached
2017/08/22 20:10:48.367828 [INF] Fragment "basket4" was cached
2017/08/22 20:10:48.367828 [INF] Fragment "basket5" was cached
2017/08/22 20:10:48.367828 [INF] Fragment "basket2" was cached
2017/08/22 20:10:48.367828 [INF] Fragment "basket" was cached
2017/08/22 20:10:48.367828 [TRC] Call fragment basket3, url: http://localhost:8081/b, duration: 999.5µs
2017/08/22 20:10:48.367828 [TRC] Call fragment basket4, url: http://localhost:8081/c, duration: 999.5µs
2017/08/22 20:10:48.367828 [TRC] Call fragment basket5, url: http://localhost:8081/d, duration: 999.5µs
2017/08/22 20:10:48.367828 [TRC] Call fragment basket2, url: http://localhost:8081/a, duration: 999.5µs
2017/08/22 20:10:48.367828 [TRC] Call fragment basket, url: https://google.de, duration: 999.5µs
2017/08/22 20:10:48.368827 [TRC] Processing complete "http://127.0.0.1:8080/favicon.ico" took "1.9983ms"
```

### Run in production
Momos is no replacement for a reverse proxy like Nginx or Apache. Only the calls to the SSI Services are cached.

## TODO
- [ ] Generate useful debug informations about the fragment structure of your page
- [ ] Collect metrics
- [ ] Add `headers` attribute to pass custom headers to the upstream proxy.
- [ ] Allow fragments to consume specific custom headers from request.

### References
- [Microservice-websites](https://gustafnk.github.io/microservice-websites/#integration-techniques)
- [Apache SSI](https://httpd.apache.org/docs/current/howto/ssi.html#page-header)

### Credits
Icon made by [author](https://www.flaticon.com/authors/dinosoftlabs) from www.flaticon.com