Sign inSign up

moonlightwork/renderer

By moonlightwork

•Updated over 8 years ago

gRPC service that renders webpage HTML using Chromeless

Image
0

655

moonlightwork/renderer repository overview

⁠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")
}

Tag summary

Content type

Image

Digest

Size

387 MB

Last updated

over 8 years ago

docker pull moonlightwork/renderer