apis

package
v0.0.0-...-89d1b08 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package apis implements the default PocketBase api services and middlewares.

Index

Constants

View Source
const (
	ContextUserKey       string = "user"
	ContextAdminKey      string = "admin"
	ContextCollectionKey string = "collection"
)

Common request context keys used by the middlewares and api handlers.

Variables

This section is empty.

Functions

func ActivityLogger

func ActivityLogger(app core.App) echo.MiddlewareFunc

ActivityLogger middleware takes care to save the request information into the logs database.

The middleware does nothing if the app logs retention period is zero (aka. app.Settings().Logs.MaxDays = 0).

func BindAdminApi

func BindAdminApi(app core.App, rg *echo.Group)

BindAdminApi registers the admin api endpoints and the corresponding handlers.

func BindCollectionApi

func BindCollectionApi(app core.App, rg *echo.Group)

BindCollectionApi registers the collection api endpoints and the corresponding handlers.

func BindFileApi

func BindFileApi(app core.App, rg *echo.Group)

BindFileApi registers the file api endpoints and the corresponding handlers.

func BindLogsApi

func BindLogsApi(app core.App, rg *echo.Group)

BindLogsApi registers the request logs api endpoints.

func BindRealtimeApi

func BindRealtimeApi(app core.App, rg *echo.Group)

BindRealtimeApi registers the realtime api endpoints.

func BindRecordApi

func BindRecordApi(app core.App, rg *echo.Group)

BindRecordApi registers the record api endpoints and the corresponding handlers.

func BindSettingsApi

func BindSettingsApi(app core.App, rg *echo.Group)

BindSettingsApi registers the settings api endpoints.

func BindUserApi

func BindUserApi(app core.App, rg *echo.Group)

BindUserApi registers the user api endpoints and the corresponding handlers.

func InitApi

func InitApi(app core.App) (*echo.Echo, error)

InitApi creates a configured echo instance with registered system and app specific routes and middlewares.

func LoadAuthContext

func LoadAuthContext(app core.App) echo.MiddlewareFunc

LoadAuthContext middleware reads the Authorization request header and loads the token related user or admin instance into the request's context.

This middleware is expected to be registered by default for all routes.

func LoadCollectionContext

func LoadCollectionContext(app core.App) echo.MiddlewareFunc

LoadCollectionContext middleware finds the collection with related path identifier and loads it into the request context.

func RequireAdminAuth

func RequireAdminAuth() echo.MiddlewareFunc

RequireAdminAuth middleware requires a request to have a valid admin Authorization header set (aka. `Authorization: Admin ...`).

func RequireAdminAuthOnlyIfAny

func RequireAdminAuthOnlyIfAny(app core.App) echo.MiddlewareFunc

RequireAdminAuthOnlyIfAny middleware requires a request to have a valid admin Authorization header set (aka. `Authorization: Admin ...`) ONLY if the application has at least 1 existing Admin model.

func RequireAdminOrOwnerAuth

func RequireAdminOrOwnerAuth(ownerIdParam string) echo.MiddlewareFunc

RequireAdminOrOwnerAuth middleware requires a request to have a valid admin or user owner Authorization header set (aka. `Authorization: Admin ...` or `Authorization: User ...`).

This middleware is similar to [apis.RequireAdminOrUserAuth()] but for the user token expects to have the same id as the path parameter `ownerIdParam` (default to "id").

func RequireAdminOrUserAuth

func RequireAdminOrUserAuth() echo.MiddlewareFunc

RequireAdminOrUserAuth middleware requires a request to have a valid admin or user Authorization header set (aka. `Authorization: Admin ...` or `Authorization: User ...`).

This middleware is the opposite of [apis.RequireGuestOnly()].

func RequireGuestOnly

func RequireGuestOnly() echo.MiddlewareFunc

RequireGuestOnly middleware requires a request to NOT have a valid Authorization header set.

This middleware is the opposite of [apis.RequireAdminOrUserAuth()].

func RequireUserAuth

func RequireUserAuth() echo.MiddlewareFunc

RequireUserAuth middleware requires a request to have a valid user Authorization header set (aka. `Authorization: User ...`).

func StaticDirectoryHandler

func StaticDirectoryHandler(fileSystem fs.FS, disablePathUnescaping bool) echo.HandlerFunc

StaticDirectoryHandler is similar to `echo.StaticDirectoryHandler` but without the directory redirect which conflicts with RemoveTrailingSlash middleware.

@see https://github.com/labstack/echo/issues/2211

Types

This section is empty.

Jump to

Keyboard shortcuts

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