Point subscribe call to correct endpoint

This commit is contained in:
Jeff 2024-09-23 15:23:20 -04:00
parent 784eccb92a
commit 2e777d3376
4 changed files with 12 additions and 5 deletions

5
api/subscribe.ts Normal file
View File

@ -0,0 +1,5 @@
import type { Response, Request } from "express"
export function subscribe(req: Request, res: Response) {
res.status(200).send()
}

View File

@ -74,7 +74,7 @@ function LandingMessage({ isSupported }: { isSupported: boolean }) {
function EnableButton({ onSubscribe }: { onSubscribe: () => void }) { function EnableButton({ onSubscribe }: { onSubscribe: () => void }) {
const { subscribeToPush, requestPermission, canSendPush } = usePush() const { subscribeToPush, requestPermission, canSendPush } = usePush()
async function subscribe() { function subscribe() {
console.log("Hey the thing was clicked wow") console.log("Hey the thing was clicked wow")
requestPermission() requestPermission()
} }
@ -85,7 +85,7 @@ function EnableButton({ onSubscribe }: { onSubscribe: () => void }) {
subscribeToPush( subscribeToPush(
urlB64ToUint8Array(applicationServerPublicKey) as any, urlB64ToUint8Array(applicationServerPublicKey) as any,
(subscription) => { (subscription) => {
fetch("/subscribe", { fetch("/api/subscribe", {
method: "POST", method: "POST",
body: JSON.stringify(subscription), body: JSON.stringify(subscription),
}) })

View File

@ -52,7 +52,7 @@ describe("when user is on iOS", () => {
permission: "default", permission: "default",
requestPermissionResult: "granted", requestPermissionResult: "granted",
}) })
await page.route("/subscribe", async (route) => { await page.route("/api/subscribe", async (route) => {
await route.fulfill() await route.fulfill()
}) })
}) })
@ -62,7 +62,7 @@ describe("when user is on iOS", () => {
}) => { }) => {
await page.goto("/") await page.goto("/")
const requestPromise = page.waitForRequest("/subscribe") const requestPromise = page.waitForRequest("/api/subscribe")
await page.getByText(/Enable notifications/).click() await page.getByText(/Enable notifications/).click()
const request = await requestPromise const request = await requestPromise
@ -74,7 +74,7 @@ describe("when user is on iOS", () => {
}) => { }) => {
await page.goto("/") await page.goto("/")
const requestPromise = page.waitForRequest("/subscribe") const requestPromise = page.waitForRequest("/api/subscribe")
await page.getByText(/Enable notifications/).click() await page.getByText(/Enable notifications/).click()
await requestPromise await requestPromise

View File

@ -3,10 +3,12 @@ import express from "express"
// notice that the result of `remix vite:build` is "just a module" // notice that the result of `remix vite:build` is "just a module"
import * as build from "./build/server/index.js" import * as build from "./build/server/index.js"
import { subscribe } from "./api/subscribe.js"
const app = express() const app = express()
app.use(express.static("build/client")) app.use(express.static("build/client"))
app.get("/api", (req, res) => res.send("HI")) app.get("/api", (req, res) => res.send("HI"))
app.post("/api/subscribe", subscribe)
// and your app is "just a request handler" // and your app is "just a request handler"
app.all("*", createRequestHandler({ build })) app.all("*", createRequestHandler({ build }))