izdi
05/21/2023, 8:41 PMimport { Client } from "@notionhq/client"
export async function onRequestPost(context) {
const notion = new Client({ auth: context.env.NOTION_INTERNAL_INTEGRATION_TOKEN })
}
Prior to that I ditched the package and used plain JS + fetch to work with API, but I need packages for more complex tasks where I can't implement in plain JS due to time constraints.meyer
05/22/2023, 3:04 PMnode-fetch
usage in the notion client. node-fetch
is not made for use with cloudflare workers. it's also unnecessary since fetch support is built in to the worker environment.
you can pass in your own fetch implementation to the client (https://github.com/makenotion/notion-sdk-js/blob/02ad37d949bed482d63a36cd9408f8a3c222bccf/src/Client.ts#L124). that'll get you halfway there. the other half would involve either preventing node-fetch
from resolving and muffling the error or resolving it to a noop. you can do this one of several ways:
1. bundle the worker yourself and do the aliasing in the bundler config
2. alias the module with your node package manager if it supports it (i.e. yarn resolutions, pnpm as well probably?)
https://cdn.discordapp.com/attachments/910978223968518144/1110221639670583316/image.png▾
meyer
05/22/2023, 3:05 PMnode-fetch
. if you're really pressed for time that would certainly do the trick.meyer
05/22/2023, 3:08 PMnode-fetch
. the API differences are negligible:
- https://github.com/node-fetch/node-fetch/blob/HEAD/docs/v2-LIMITS.md
- https://github.com/node-fetch/node-fetch/blob/HEAD/docs/v3-LIMITS.mdbennycondon
05/23/2023, 12:59 AMJames
05/23/2023, 1:02 AMJames
05/23/2023, 1:02 AMbennycondon
05/23/2023, 1:06 AM1234qwerty
05/23/2023, 9:46 AMLarry
05/23/2023, 10:38 AMLarry
05/23/2023, 10:40 AM1234qwerty
05/23/2023, 10:40 AM1234qwerty
05/23/2023, 10:41 AMLarry
05/23/2023, 10:44 AM/custom-router/[[route]]
while still using other standard file-based routes /api
, /api/login
, etc. Then inside that /custom-router
onRequest
handler you could use the code from that "Native [not] Router".HardAtWork
05/23/2023, 10:44 AMLarry
05/23/2023, 10:45 AMkian
05/23/2023, 11:38 AMkian
05/23/2023, 11:38 AMmicromashor
05/24/2023, 5:50 PM/_worker.js
, so I want to bundle everything in that file so none of the backend code is exposed publiclymicromashor
05/24/2023, 5:51 PMtsc
, as it looks like the types for the Node compatibility APIs are not included in @cloudflare/workers-types
kian
05/24/2023, 5:54 PMesbuild
and marks the node:
modules as externalkian
05/24/2023, 5:55 PMtsc
thoughSkye
05/24/2023, 5:55 PMmicromashor
05/24/2023, 5:58 PM"@cloudflare/workers-types": "^4.20230321.0",
Skye
05/24/2023, 5:58 PMSkye
05/24/2023, 5:59 PMSkye
05/24/2023, 5:59 PMmicromashor
05/24/2023, 6:00 PMmicromashor
05/24/2023, 6:02 PMnodejs_compat
flag in the pages settings, but that doesn't change anything about the installed npm package where tsc
is getting the type declarationsSkye
05/24/2023, 6:03 PMjson
"types": ["@cloudflare/workers-types/2022-08-04"]
Then you'll get workers types for the compat date of 2022-08-04