Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iamelevich/pocketbase-plugin-proxy
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.
https://github.com/iamelevich/pocketbase-plugin-proxy
pocketbase pocketbase-plugins proxy
Last synced: 24 days ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/iamelevich/pocketbase-plugin-proxy
- Owner: iamelevich
- License: mit
- Created: 2023-03-19T22:32:42.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-06T07:52:35.000Z (8 months ago)
- Last Synced: 2024-04-06T08:33:32.571Z (8 months ago)
- Topics: pocketbase, pocketbase-plugins, proxy
- Language: Go
- Homepage:
- Size: 128 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-pocketbase - GitHub
- awesome-pocketbase - GitHub
- awesome-pocketbase - Proxy - Proxy requests to another other host. Can be useful when you want to use separate server as frontend (like Next.js), but serve everything with same port. ![GitHub Repo stars](https://img.shields.io/github/stars/iamelevich/pocketbase-plugin-proxy) (Native Go Plugins)
README
[![Test](https://github.com/iamelevich/pocketbase-plugin-proxy/actions/workflows/test.yml/badge.svg)](https://github.com/iamelevich/pocketbase-plugin-proxy/actions/workflows/test.yml)
[![codecov](https://codecov.io/github/iamelevich/pocketbase-plugin-proxy/graph/badge.svg?token=MAXWWCGHWD)](https://codecov.io/github/iamelevich/pocketbase-plugin-proxy)* [Overview](#overview)
* [Requirements](#requirements)
* [Installation](#installation)
* [Example](#example)
* [pocketbase\_plugin\_proxy](#pocketbasepluginproxy)
* [Index](#index)
* [func DefaultSkipper](#func-defaultskipper)
* [type Options](#type-options)
* [type Plugin](#type-plugin)
* [func MustRegister](#func-mustregister)
* [func Register](#func-register)
* [func \(\*Plugin\) SetSkipper](#func-plugin-setskipper)
* [func \(\*Plugin\) Validate](#func-plugin-validate)
* [Contributing](#contributing)
* [Process](#process)
* [Development setup](#development-setup)
* [Testing](#testing)
* [Linting](#linting)
* [Docs update in README](#docs-update-in-readme)# 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
- [Pocketbase](https://github.com/pocketbase/pocketbase)
## Installation
```bash
go get github.com/iamelevich/pocketbase-plugin-proxy
```## Example
You can check examples in [examples folder](/examples)
```go
package mainimport (
"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
```go
import "github.com/iamelevich/pocketbase-plugin-proxy"
```## Index
- [func DefaultSkipper\(c echo.Context\) bool](<#DefaultSkipper>)
- [type Options](<#Options>)
- [type Plugin](<#Plugin>)
- [func MustRegister\(app core.App, options \*Options\) \*Plugin](<#MustRegister>)
- [func Register\(app core.App, options \*Options\) \(\*Plugin, error\)](<#Register>)
- [func \(p \*Plugin\) SetSkipper\(skipper middleware.Skipper\)](<#Plugin.SetSkipper>)
- [func \(p \*Plugin\) Validate\(\) error](<#Plugin.Validate>)```go
func DefaultSkipper(c echo.Context) bool
```DefaultSkipper skip proxy middleware for requests, where path starts with /\_/ or /api/.
Options defines optional struct to customize the default plugin behavior.
```go
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
}
``````go
type Plugin struct {
// contains filtered or unexported fields
}
``````go
func MustRegister(app core.App, options *Options) *Plugin
```MustRegister is a helper function that registers plugin and panics if error occurred.
```go
func Register(app core.App, options *Options) (*Plugin, error)
```Register registers plugin.
### func \(\*Plugin\) [SetSkipper]()```go
func (p *Plugin) SetSkipper(skipper middleware.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 echo.Context) bool {
return c.Request().URL.Path == "/my-super-secret-route"
})
```
### func \(\*Plugin\) [Validate]()```go
func (p *Plugin) Validate() error
```Validate plugin options. Return error if some option is invalid.
Generated by [gomarkdoc]()
# Contributing
This pocketbase plugin is free and open source project licensed under the [MIT License](LICENSE.md).
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 [asdf](https://asdf-vm.com/#/core-manage-asdf-vm) and plugins for tools listed in [.tool-versions](.tool-versions) file.
- This repo also uses [asdf-direnv](https://github.com/asdf-community/asdf-direnv). Install it and run `direnv allow` in the repo root.
- Setup `pre-commit` hooks with `pre-commit install -t commit-msg -t pre-commit`## Testing
- Run `task test` to run tests
- Run `task test:report` to run tests and get coverage report in `./coverage.html`## Linting
- Run `task lint` to run linters
## Docs update in README
- Run `task docs` to update docs in README (it will also install [gomarkdoc](https://github.com/princjef/gomarkdoc))