Skip to content

docs: url without pathName on server listen #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/content/docs/api/setup-server/listen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ The pre-defined strategies are available as the second argument of the custom ca
```js
server.listen({
onUnhandledRequest(request, print) {

const url = new URL(request.url)

// Ignore requests to fetch static assets.
if (request.url.pathname.includes('/assets/')) {
if (url.pathname.includes('/assets/')) {
return
}

// Skip non-server API requests
if (url.origin !== process.env.API_URL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this from the example, it's too specific. It relies on the user having the API_URL env variable and even being familiar with the concept of env variables. Let's keep the example to the necessary minimum 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw your example with env variable

if (process.env.NODE_ENV !== 'development') {
and thought it was appropriate

I have other requests running on the server that don't need to be mocked, i believe that if this example had been and indexed by search, I wouldn't have spent 15 minutes looking for how to do it in issue :)

what if we moved it to faq with our h2 title like - "How to control or manage requests to different domains" ?

return
}

Expand Down