Point subscribe call to correct endpoint
This commit is contained in:
parent
784eccb92a
commit
2e777d3376
|
|
@ -0,0 +1,5 @@
|
||||||
|
import type { Response, Request } from "express"
|
||||||
|
|
||||||
|
export function subscribe(req: Request, res: Response) {
|
||||||
|
res.status(200).send()
|
||||||
|
}
|
||||||
|
|
@ -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),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 }))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue