gRPC service that renders webpage HTML using Chromeless
655
Renderer is a gRPC service that renders webpage HTML using the Chromeless package. It was inspired by the chromeless-prerender project.
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.
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.
docker-compose up # add `--build` to force a rebuild, `-d` to run in background
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")
}
Content type
Image
Digest
Size
387 MB
Last updated
over 8 years ago
docker pull moonlightwork/renderer