The provided code defines a server application using the Hono framework on Cloudflare Workers, integrated with the Expo SDK for handling push notifications.
- Dependencies: The code uses
hono
for the server framework andexpo-server-sdk
for handling Expo push notifications. - Middleware: Three middlewares are used:
poweredBy
: Removes or customizes theX-Powered-By
header.cors
: Enables CORS (Cross-Origin Resource Sharing).- Custom Authorization Middleware: Checks the
Authorization
header against an environment variableAUTHORIZATION
. If it doesn't match, it returns a401 Unauthorized
response.
- GET / Returns a simple greeting message, "Hello IXO!", to test server running.
- GET /test/:token A route handled by Notifications.sendTestNotification. It sends a test push notification to an Expo push token.
- GET /receipt/:ticket Handled by Notifications.fetchTicketReceipt. It retrieves the receipt for a previously sent push notification based on its ticket.
- Ensure you have Cloudflare Workers account and CLI configured.
- Copy
example wrangler.toml
aswrangler.toml
- Set the
AUTHORIZATION
variable in the newwrangler.toml
file with your secret key.
yarn install
yarn dev
yarn test
yarn deploy
/src/handlers/notifications.ts:20
- TypeError: Illegal invocation
at Expo2. (index.js:11319:54)
at Generator.next ()
at index.js:11159:71
at new Promise ()
at __awaiter (index.js:11141:14)
at Expo2.requestAsync (index.js:11297:16)
at Expo2. (index.js:11198:35)
at Generator.next ()
at index.js:11159:71
at new Promise () {
stack: TypeError: Illegal invocation
at Expo2.<anonym…ndex.js:11159:71
at new Promise (),
message: Illegal invocation
}
- TypeError: Illegal invocation