Reputation: 23
I'm trying to set up a custom route using PocketBase Hooks but encountering a 404 Not Found
error when accessing the endpoint localhost:8090/api/hello/world
.
When I visit http://localhost:8090/api/hello/world
, I expect to receive:
{
"message": "Hello world"
}
Instead, I get the following:
{
"code": 404,
"message": "Not Found.",
"data": {}
}
I'm using PocketBase in combination with Docker. Here's my setup:
docker-compose.yml
:
services:
pocketbase:
build:
context: "."
dockerfile: Dockerfile.pocketbase
restart: unless-stopped
ports:
- 8090:8090
volumes:
- "./data:/pb/pb_data"
- "./hooks:/pb/pb_hooks"
Dockerfile.pocketbase
:
FROM alpine:latest
ARG PB_VERSION=0.22.26
RUN apk add --no-cache \
unzip \
ca-certificates
# download and unzip PocketBase
ADD https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip /tmp/pb.zip
RUN unzip /tmp/pb.zip -d /pb/
VOLUME /pb/pb_hooks
VOLUME /pb/pb_data
EXPOSE 8090
CMD ["/pb/pocketbase", "serve", "--http=0.0.0.0:8090", "--hooksDir=./pb_hooks" ]
The hook I'm trying to use is located at ./hooks/main.pb.js
and contains the following code:
routerAdd("GET", "/hello/{name}", (e) => {
let name = e.request.pathValue("name");
return e.json(200, { message: "Hello " + name });
});
How can I resolve this 404 Not Found
error and successfully use my custom PocketBase hook? Are there any additional steps required to enable the hooks?
Upvotes: 0
Views: 27