Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Ability to proxy requests to another endpoint #4276

Open
rodydavis opened this issue Jan 31, 2024 · 2 comments
Open

Feature Request: Ability to proxy requests to another endpoint #4276

rodydavis opened this issue Jan 31, 2024 · 2 comments

Comments

@rodydavis
Copy link

rodydavis commented Jan 31, 2024

Problem

Right now if you want to extend pocketbase as a framework without Go via JS then there are some limitations when it comes to routing. Curious if it would be possible to include an API similar to static files that can use a wild card to proxy requests too.

routerAdd("GET", "/*", $apis.staticDirectoryHandler("/path/to/public", false))

Possible Solution

This would need to support more than just GET. For example the API could be:

routerAdd("*", "/*", $apis.singleHostReverseProxy(
     scheme: "http",
     host: "localhost:4321",
))

Here is an example that works if you compile with GO:

package main

import (
	"log"
	"net/http/httputil"
	"net/url"

	"github.com/labstack/echo/v5"
	"github.com/pocketbase/pocketbase"
	"github.com/pocketbase/pocketbase/core"
)

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

    app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
        proxy := httputil.NewSingleHostReverseProxy(&url.URL{
			Scheme: "http",
			Host:   "localhost:4321",
		})
		e.Router.Any("/*", echo.WrapHandler(proxy))
		e.Router.Any("/", echo.WrapHandler(proxy))
        return nil
    })

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

I also wrote a blog post on how I am doing this with Astro:
https://rodydavis.com/posts/astro-ssr-pocketbase-single-server

The downside of this is I believe it does not support auto updates ./pocketbase update and requires GO knowledge to implement.

@rodydavis rodydavis changed the title [Feature Request] - Ability to proxy requests to another endpoint Feature Request: Ability to proxy requests to another endpoint Jan 31, 2024
@awd3321
Copy link

awd3321 commented Mar 1, 2024

If you go to http://127.0.0.1:8090/_/#/login it can be easily exposed admin login

@tegarimansyah
Copy link

Hmm, not sure but why not we reverse the request. So user request to astro server and in some path, it will proxy to pocketbase?

https://stackoverflow.com/questions/73212935/astro-how-to-proxy-service-calls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants