grazer

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2023 License: MIT Imports: 13 Imported by: 0

README

grazer

🌱🦓

What does it do?

Grazer implements a queued revalidation of invalidated route paths for the combination of Neos and Next.js. Instead of figuring out the minimal set of paths (documents) to revalidate, we rather want to first revalidate the directly changed documents and revalidate all other paths after that. Since Next.js and Neos itself are not suitable to run a queue and we have some special needs for prioritization / uniqueness, we created this small server based around a custom priority queue. To make deployment of Neos and Next.js easier, it also does an initial revalidate of all documents after a configurable delay.

Installation

  • Deploy via Docker or run the binary
  • Set flags / env vars for your specific environment
  • Forward invalidate requests from Networkteam.Neos.Next to /api/revalidate

Command reference

NAME:
   grazer - Handle invalidates from Neos CMS and revalidation in Next.js

USAGE:
   grazer [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --address value                                              Address for HTTP server to listen on (default: ":3100") [$GZ_ADDRESS]
   --revalidate-token value                                     A secret token to use for revalidation [$GZ_REVALIDATE_TOKEN]
   --next-revalidate-url value                                  The full URL to call to revalidate a page in Next.js [$GZ_NEXT_REVALIDATE_URL]
   --revalidate-batch-size value                                The number of documents to send for revalidation in one batch to Next.js (default: 1) [$GZ_REVALIDATE_BATCH_SIZE]
   --revalidate-timeout value                                   Timeout for revalidation requests (default: 15s) [$GZ_REVALIDATE_TIMEOUT]
   --neos-base-url value                                        The base URL of the Neos CMS instance for fetching documents from the content API [$GZ_NEOS_BASE_URL]
   --public-base-url value                                      The publicly accessible base URL for sending correct proxy headers to Neos (for multi-site setups) [$GZ_PUBLIC_BASE_URL]
   --fetch-timeout value                                        Timeout for fetching from the Neos content API (default: 15s) [$GZ_FETCH_TIMEOUT]
   --initial-revalidate-delay value                             Delay before an initial revalidation of all pages, set to 0 to disable (default: 15s) [$GZ_INITIAL_REVALIDATE_DELAY]
   --revalidate-schedule value [ --revalidate-schedule value ]  Add a cron schedule to trigger revalidation of all pages (e.g. "@hourly", "@daily", "30 * * * *") [$GZ_REVALIDATE_SCHEDULE]
   --verbose                                                    Enable verbose logging (default: false) [$GZ_VERBOSE]
   --help, -h                                                   show help

Caveats

  • There is no persistence yet - a restart will (cleanly) stop processing of the queue. But this should not be an issue with the full initial revalidation.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocumentsItem

type DocumentsItem struct {
	RoutePath string `json:"routePath"`
}

type DocumentsResponse

type DocumentsResponse struct {
	Documents []DocumentsItem `json:"documents"`
}

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

func NewFetcher

func NewFetcher(opts FetcherOpts) *Fetcher

func (*Fetcher) ListDocuments

func (f *Fetcher) ListDocuments(ctx context.Context) (*DocumentsResponse, error)

type FetcherOpts

type FetcherOpts struct {
	Timeout       time.Duration
	NeosBaseURL   string
	PublicBaseURL string

	Transport http.RoundTripper
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(opts HandlerOpts) *Handler

func (*Handler) FullRevalidate added in v0.4.0

func (h *Handler) FullRevalidate(ctx context.Context) error

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Handler) ShutdownAndWait

func (h *Handler) ShutdownAndWait()

type HandlerOpts

type HandlerOpts struct {
	RevalidateToken string

	Revalidator         *Revalidator
	Fetcher             *Fetcher
	RevalidateBatchSize int
}

type Revalidator

type Revalidator struct {
	// contains filtered or unexported fields
}

func NewRevalidator

func NewRevalidator(opts RevalidatorOpts) *Revalidator

func (*Revalidator) Revalidate

func (r *Revalidator) Revalidate(ctx context.Context, routePaths []string) error

type RevalidatorOpts

type RevalidatorOpts struct {
	URL             string
	RevalidateToken string
	Timeout         time.Duration

	Transport http.RoundTripper
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL