[DEPRECATED] gRPC service that renders webpage HTML using Chromeless
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
Dockerfile
LICENSE
README.md
docker-compose.yml
makefile
package.json
renderer.pb.go
renderer.proto
server.js
supervisord.conf
yarn.lock

README.md

Renderer

Docker Automated build Moonlight contractors Godoc Reference

Renderer is a gRPC service that renders webpage HTML using the Chromeless package. It was inspired by the chromeless-prerender project.

Motivation

At Moonlight, we needed to do prerendering of our Javascript single-page application. We wanted to use prerender.io, but it didn't seem maintained enough to be compatible with the latest Javascript. We put together this renderer project so that we could just run one (or more) containers inside of our Kubernetes cluster for rendering. We manage caching on the client, so no explicit caching is added to this server.

Contributing

Changes are welcome. If you modify the proto file, please regenerate and commit the built protoc files using make. This allows this package to be go get-able for use in clients that interact with the server.

Usage

Booting server in Docker

docker-compose up # add `--build` to force a rebuild, `-d` to run in background

Go Client

package main

import (
	"fmt"

	"golang.org/x/net/context"

	"github.com/moonlightwork/renderer"
	"google.golang.org/grpc"
)

func main() {
	// Create connection (insecure)
	opts := []grpc.DialOption{grpc.WithInsecure()}
	conn, err := grpc.Dial("localhost:3000", opts...)
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	// Create client
	client := renderer.NewRendererServiceClient(conn)

	// Try health check endpoint to make sure container is online
	_, err = client.CheckHealth(context.Background(), &renderer.Empty{})
	if err != nil {
		panic(err)
	}
	fmt.Println("✅ API Online")

	// Try rendering a URL
	res, err := client.Render(context.Background(), &renderer.Request{Url: "https://www.moonlightwork.com/about"})
	if err != nil {
		panic(err)
	}

	// Printing HTML to show that it's been rendered
	fmt.Printf("\n\n%v\n\n", res.Data)

	fmt.Println("💡 Successfully fetched HTML")
}