pocketbase_plugin_proxy

package module
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 8 Imported by: 0

README

Test codecov

Overview

This plugin allow proxify requests to other host. It can be useful if you want to use separate server as frontend but use one address for both frontend and backend.

Requirements

Installation

go get github.com/iamelevich/pocketbase-plugin-proxy

Example

You can check examples in examples folder

package main

import (
	"log"

	proxyPlugin "github.com/iamelevich/pocketbase-plugin-proxy"
	"github.com/pocketbase/pocketbase"
)

func main() {
	app := pocketbase.New()

	// Setup proxy plugin
	proxyPlugin.MustRegister(app, &proxyPlugin.Options{
		Enabled: true,
		Url:     "http://localhost:3000",
	})

	if err := app.Start(); err != nil {
		log.Fatal(err)
	}
}

pocketbase_plugin_proxy

import "github.com/iamelevich/pocketbase-plugin-proxy"

Index

func DefaultSkipper

func DefaultSkipper(c *core.RequestEvent) bool

DefaultSkipper skip proxy middleware for requests, where path starts with /_/ or /api/.

type Options

Options defines optional struct to customize the default plugin behavior.

type Options struct {
    // Enabled defines if proxy should be enabled.
    Enabled bool

    //Url to the target.
    //
    //Only http and https links are supported.
    Url string

    // Are proxy logs enabled?
    ProxyLogsEnabled bool
}

type Plugin

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

func MustRegister
func MustRegister(app core.App, options *Options) *Plugin

MustRegister is a helper function that registers plugin and panics if error occurred.

func Register
func Register(app core.App, options *Options) (*Plugin, error)

Register registers plugin.

func (*Plugin) SetSkipper
func (p *Plugin) SetSkipper(skipper Skipper)

SetSkipper set skipper function that should return true if that route shouldn't be proxied.

If not set, the DefaultSkipper is used:

If set - you should also control the middleware behavior for /_/ and /api/ routes.

Example:

plugin := proxyPlugin.MustRegister(app, &proxyPlugin.Options{
	Enabled: true,
	Url:     "http://localhost:3000",
})
plugin.SetSkipper(func(c *core.RequestEvent) bool {
	return c.Request.URL.Path == "/my-super-secret-route"
})

func (*Plugin) Validate
func (p *Plugin) Validate() error

Validate plugin options. Return error if some option is invalid.

type Skipper

type Skipper func(c *core.RequestEvent) bool

Generated by gomarkdoc

Contributing

This pocketbase plugin is free and open source project licensed under the MIT License. You are free to do whatever you want with it, even offering it as a paid service.

Process

  • Fork the repo
  • Create a new branch
  • Make your changes
  • Create a pull request
  • Wait for review
  • Make changes if needed
  • Merge
  • Celebrate :)

Development setup

  • Install mise and run mise install.
  • Setup prek hooks with prek install -t commit-msg -t pre-commit

Testing

  • Run mise run test to run tests
  • Run mise run test-report to run tests and get coverage report in ./coverage.html

Linting

  • Run mise run lint to run linters

Docs update in README

  • Run mise run docs to update docs in README (it will also install gomarkdoc)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSkipper added in v0.15.0

func DefaultSkipper(c *core.RequestEvent) bool

DefaultSkipper skip proxy middleware for requests, where path starts with /_/ or /api/.

Types

type Options

type Options struct {
	// Enabled defines if proxy should be enabled.
	Enabled bool

	//Url to the target.
	//
	//Only http and https links are supported.
	Url string

	// Are proxy logs enabled?
	ProxyLogsEnabled bool

	// Headers to add to the request.
	Headers map[string]string
}

Options defines optional struct to customize the default plugin behavior.

type Plugin

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

func MustRegister

func MustRegister(app core.App, options *Options) *Plugin

MustRegister is a helper function that registers plugin and panics if error occurred.

func Register

func Register(app core.App, options *Options) (*Plugin, error)

Register registers plugin.

func (*Plugin) SetSkipper added in v0.15.0

func (p *Plugin) SetSkipper(skipper Skipper)

SetSkipper set skipper function that should return true if that route shouldn't be proxied.

If not set, the DefaultSkipper is used:

If set - you should also control the middleware behavior for /_/ and /api/ routes.

Example:

plugin := proxyPlugin.MustRegister(app, &proxyPlugin.Options{
	Enabled: true,
	Url:     "http://localhost:3000",
})
plugin.SetSkipper(func(c *core.RequestEvent) bool {
	return c.Request.URL.Path == "/my-super-secret-route"
})

func (*Plugin) Validate

func (p *Plugin) Validate() error

Validate plugin options. Return error if some option is invalid.

type Skipper added in v0.17.0

type Skipper func(c *core.RequestEvent) bool

Directories

Path Synopsis
examples
base command

Jump to

Keyboard shortcuts

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