diff --git a/api/subscribe.ts b/api/subscribe.ts new file mode 100644 index 0000000..1b4a57e --- /dev/null +++ b/api/subscribe.ts @@ -0,0 +1,5 @@ +import type { Response, Request } from "express" + +export function subscribe(req: Request, res: Response) { + res.status(200).send() +} diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 5fcc2d7..feee22e 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -74,7 +74,7 @@ function LandingMessage({ isSupported }: { isSupported: boolean }) { function EnableButton({ onSubscribe }: { onSubscribe: () => void }) { const { subscribeToPush, requestPermission, canSendPush } = usePush() - async function subscribe() { + function subscribe() { console.log("Hey the thing was clicked wow") requestPermission() } @@ -85,7 +85,7 @@ function EnableButton({ onSubscribe }: { onSubscribe: () => void }) { subscribeToPush( urlB64ToUint8Array(applicationServerPublicKey) as any, (subscription) => { - fetch("/subscribe", { + fetch("/api/subscribe", { method: "POST", body: JSON.stringify(subscription), }) diff --git a/e2e/install.spec.ts b/e2e/install.spec.ts index 3a86133..05379cb 100644 --- a/e2e/install.spec.ts +++ b/e2e/install.spec.ts @@ -52,7 +52,7 @@ describe("when user is on iOS", () => { permission: "default", requestPermissionResult: "granted", }) - await page.route("/subscribe", async (route) => { + await page.route("/api/subscribe", async (route) => { await route.fulfill() }) }) @@ -62,7 +62,7 @@ describe("when user is on iOS", () => { }) => { await page.goto("/") - const requestPromise = page.waitForRequest("/subscribe") + const requestPromise = page.waitForRequest("/api/subscribe") await page.getByText(/Enable notifications/).click() const request = await requestPromise @@ -74,7 +74,7 @@ describe("when user is on iOS", () => { }) => { await page.goto("/") - const requestPromise = page.waitForRequest("/subscribe") + const requestPromise = page.waitForRequest("/api/subscribe") await page.getByText(/Enable notifications/).click() await requestPromise diff --git a/server.ts b/server.ts index f368ead..ce3a4c3 100644 --- a/server.ts +++ b/server.ts @@ -3,10 +3,12 @@ import express from "express" // notice that the result of `remix vite:build` is "just a module" import * as build from "./build/server/index.js" +import { subscribe } from "./api/subscribe.js" const app = express() app.use(express.static("build/client")) app.get("/api", (req, res) => res.send("HI")) +app.post("/api/subscribe", subscribe) // and your app is "just a request handler" app.all("*", createRequestHandler({ build }))