Skip to content

Implement 404 redirect handling with middleware #16563

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 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8216543
Update pnpm-lock.yaml
dannyroosevelt Apr 29, 2025
7c06099
Fixing bad /apps redirect, adding catch-all redirect
dannyroosevelt Apr 30, 2025
f22bcbc
Update pnpm-lock.yaml
dannyroosevelt Apr 30, 2025
4173b1a
Merge branch 'master' into danny/fixing-docs-apps-redirect
dannyroosevelt Apr 30, 2025
c9d3129
Merge branch 'master' into danny/fixing-docs-apps-redirect
dannyroosevelt Apr 30, 2025
a30008a
Escaping unsafe characters and pnpm lock
dannyroosevelt Apr 30, 2025
354d379
Merge branch 'master' into danny/fixing-docs-apps-redirect
dannyroosevelt Apr 30, 2025
e4dca75
Update 404.tsx
dannyroosevelt Apr 30, 2025
9b41e49
Merge branch 'danny/fixing-docs-apps-redirect' of github.com:Pipedrea…
dannyroosevelt Apr 30, 2025
579e1c6
Merge branch 'danny/fixing-docs-apps-redirect' of github.com:Pipedrea…
dannyroosevelt Apr 30, 2025
9600bde
Update pnpm-lock.yaml
dannyroosevelt Apr 30, 2025
787970c
Delete apps.mdx
dannyroosevelt Apr 30, 2025
9780aab
Updating header anchor tags
dannyroosevelt May 6, 2025
36c08d5
Merge branch 'master' into danny/fixing-docs-apps-redirect
dannyroosevelt May 6, 2025
a7e2163
Update users.mdx
dannyroosevelt May 6, 2025
2326e48
Merge branch 'danny/fixing-docs-apps-redirect' of github.com:Pipedrea…
dannyroosevelt May 6, 2025
24ef2b6
Modifying 404 handling
dannyroosevelt May 6, 2025
a260ae4
Add redirects for /apps/apps/ and /integrations/ paths
dannyroosevelt May 6, 2025
bfd8748
Linting
dannyroosevelt May 6, 2025
4b972dd
Add 404 redirect handling with middleware
dannyroosevelt May 6, 2025
0e9a3f3
Update middleware.ts
dannyroosevelt May 6, 2025
40003d3
Merge branch 'master' into danny/404-redirect-handling
dannyroosevelt May 6, 2025
c8e00d0
Update users.mdx
dannyroosevelt May 6, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ docs/.vuepress/dist
components/**/package-lock.json
/packages/evals/
/packages/sdk/examples/.next/

**/.claude/settings.local.json
41 changes: 41 additions & 0 deletions docs-v2/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"

/**
* Middleware to handle 404s by redirecting to the home page
* Instead of showing a 404 error page, we redirect to the root
* Using a 301 (permanent) redirect for better SEO handling
*/
export function middleware(request: NextRequest) {
// We only want to handle 404s, not other pages
// This check isn't foolproof but helps avoid redirecting existing pages
const pathname = request.nextUrl.pathname

// Check if this is a static asset or API route - we don't want to redirect these
if (
pathname.startsWith("/_next") ||
pathname.startsWith("/api/") ||
pathname.startsWith("/images/") ||
pathname.includes(".") // Likely a file, e.g. favicon.ico
) {
return NextResponse.next()
}

// Return a 301 (permanent) redirect to the home page
return NextResponse.redirect(new URL("/", request.url), 301)
}

// Configure which paths this middleware will run on
// This runs the middleware on paths that don't exist in our app
export const config = {
matcher: [
/*
* Match all request paths except for:
* 1. Existing pages in the pages directory
* 2. API routes
* 3. Static files (images, etc)
* 4. System paths like _next, favicon.ico, etc.
*/
"/((?!_next|api|images|favicon.ico).*)",
],
}

Check failure on line 41 in docs-v2/middleware.ts

View workflow job for this annotation

GitHub Actions / Lint Code Base

Newline required at end of file but not found
19 changes: 14 additions & 5 deletions docs-v2/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default withNextra({
},
async redirects() {
return [
{
source: "/apps/apps/",
destination: "/apps/",
permanent: true,
},
{
source: "/v3/",
destination: "/",
Expand Down Expand Up @@ -69,11 +74,6 @@ export default withNextra({
destination: "https://pipedream.com/apps/",
permanent: true,
},
{
source: "/apps/:path*/",
destination: "https://pipedream.com/apps/:path*/",
permanent: true,
},
{
source: "/support/",
destination: "https://pipedream.com/support/",
Expand Down Expand Up @@ -481,6 +481,11 @@ export default withNextra({
destination: "/integrations/oauth-clients/",
permanent: true,
},
{
source: "/integrations/",
destination: "/apps/",
permanent: true,
},
{
source: "/integrations/:path*/",
destination: "/apps/:path*/",
Expand Down Expand Up @@ -561,6 +566,10 @@ export default withNextra({
source: "/api-demo-connect/accounts/:id/",
destination: "/api/demo-connect/accounts/:id",
},
{
source: "/workflows/errors/",
destination: "/workflows/building-workflows/errors/",
},
];
},
env: {
Expand Down
37 changes: 37 additions & 0 deletions docs-v2/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useEffect } from "react"
import { useRouter } from "next/router"

/**
* Custom 404 component - this is a fallback in case the middleware redirect doesn't work
* The middleware.ts file handles the main redirect logic with a 301 status code
* This component will only be shown if the middleware fails to redirect
*/
export default function Custom404() {
const router = useRouter()

useEffect(() => {
// Fallback redirect if middleware didn't handle it
// Using a short timeout to ensure middleware has a chance to run first
const redirectTimeout = setTimeout(() => {
router.replace("/")
}, 100)

return () => clearTimeout(redirectTimeout)
}, [
router,
])

return (
<div style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
height: "100vh",
}}>
<div>
<h1>Page not found</h1>
<p>Redirecting to home page...</p>
</div>
</div>
)
}
79 changes: 0 additions & 79 deletions docs-v2/pages/apps/apps.mdx

This file was deleted.

18 changes: 9 additions & 9 deletions docs-v2/pages/connect/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const pd = createBackendClient({

You'll primarily use the browser SDK to let your users securely connect apps from your frontend. Here, you

1. [Create a short-lived token on your server](#create-a-new-token)
1. [Create a short-lived token on your server](#create-token)
2. Initiate auth with that token to securely connect an account for a specific user

Here's a Next.js example [from our quickstart](/connect/managed-auth/quickstart/):
Expand Down Expand Up @@ -240,7 +240,7 @@ Your app will initiate the account connection flow for your end users in your fr

See [the Connect tokens docs](/connect/tokens/) for more information.

#### Create a new token
#### Create token

```
POST /{project_id}/tokens
Expand Down Expand Up @@ -999,7 +999,7 @@ curl -X DELETE "https://api.pipedream.com/v1/connect/{project_id}/accounts/{acco

Pipedream returns a `204 No Content` response on successful account deletion

#### Delete an end user
#### Delete end user

Delete an end user, all their connected accounts, and any deployed triggers.

Expand Down Expand Up @@ -2688,7 +2688,7 @@ curl -X GET \
}
```

#### Delete a deployed trigger
#### Delete deployed trigger

Delete deployed trigger for a given user.

Expand Down Expand Up @@ -2798,7 +2798,7 @@ curl -X DELETE \
Pipedream returns a `204 No Content` response on successful deletion


#### Retrieve the events emitted by a deployed trigger
#### Retrieve events emitted by deployed trigger

Retrieve a list of the last events that a deployed trigger emitted.

Expand Down Expand Up @@ -2995,7 +2995,7 @@ curl -X GET \
}
```

#### Retrieve the webhooks listening to a deployed trigger
#### Retrieve webhooks listening to deployed trigger

Retrieve the list of webhook URLs listening to a deployed trigger.

Expand Down Expand Up @@ -3116,7 +3116,7 @@ curl -X GET \
}
```

#### Update the webhooks listening to a deployed trigger
#### Update webhooks listening to deployed trigger

Update the list of webhook URLs that will listen to a deployed trigger.

Expand Down Expand Up @@ -3255,7 +3255,7 @@ curl -X PUT \
}
```

#### Retrieve the workflows listening to a deployed trigger
#### Retrieve workflows listening to deployed trigger

Retrieve the list of workflow IDs listening to a deployed trigger.

Expand Down Expand Up @@ -3377,7 +3377,7 @@ curl -X GET \
}
```

#### Update the workflows listening to a deployed trigger
#### Update workflows listening to deployed trigger

Update the list of workflows that will listen to a deployed trigger.

Expand Down
2 changes: 1 addition & 1 deletion docs-v2/pages/connect/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ Refer to the [full Connect API reference](/connect/api/#deploy-a-trigger) to lis
- Many event sources attempt to retrieve a small set of historical events on deploy to provide visibility into the event shape for end users and developers
- Exposing real test events make it easier to consume the event in downstream systems without requiring users to trigger real events ([more info](/components/contributing/guidelines/#surfacing-test-events))
- However, this results in emitting those events to the listening webhook immediately, which may not always be ideal, depending on your use case
- If you'd like to avoid emitting historical events, you can deploy a trigger without defining a `webhook_url`, then [update the listening webhooks for the deployed trigger](/connect/api/#update-the-webhooks-listening-to-a-deployed-trigger) after roughly a minute
- If you'd like to avoid emitting historical events, you can deploy a trigger without defining a `webhook_url`, then [update the listening webhooks for the deployed trigger](/connect/api/#update-webhooks-listening-to-deployed-trigger) after roughly a minute


### Native triggers
Expand Down
2 changes: 1 addition & 1 deletion docs-v2/pages/connect/environments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The `development` environment is not intended for production use with your custo

## How to specify the environment

You specify the environment when [creating a new Connect token](/connect/api/#create-a-new-token) with the Pipedream SDK or API. When users successfully connect their account, Pipedream saves the account credentials (API key, access token, etc.) for that `external_user_id` in the specified environment.
You specify the environment when [creating a new Connect token](/connect/api/#create-token) with the Pipedream SDK or API. When users successfully connect their account, Pipedream saves the account credentials (API key, access token, etc.) for that `external_user_id` in the specified environment.

Always set the environment when you create the SDK client:

Expand Down
2 changes: 1 addition & 1 deletion docs-v2/pages/connect/managed-auth/connect-link.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ https://pipedream.com/_static/connect.html?token={token}&connectLink=true&app={a

## Success and error redirect URLs

To automatically redirect users somewhere after they complete the connection flow (or if an error occurs), define the `success_redirect_uri` and `error_redirect_uri` parameters during token creation. [See the API docs](/connect/api/#create-a-new-token) for details.
To automatically redirect users somewhere after they complete the connection flow (or if an error occurs), define the `success_redirect_uri` and `error_redirect_uri` parameters during token creation. [See the API docs](/connect/api/#create-token) for details.

In the absence of these URLs, Pipedream will redirect the user to a Pipedream-hosted success or error page at the end of the connection flow.
4 changes: 2 additions & 2 deletions docs-v2/pages/connect/managed-auth/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ In the code below you can see how we generate a Connect token for an example use
Once you have a token, return it to your frontend to start the account connection flow for the user, or redirect them to a Pipedream-hosted URL with [Connect Link](#or-use-connect-link).

<Callout type="info">
Refer to the API docs for [full set of parameters you can pass](/connect/api/#create-a-new-token) in the `ConnectTokenCreate` call.
Refer to the API docs for [full set of parameters you can pass](/connect/api/#create-token) in the `ConnectTokenCreate` call.
</Callout>

### Connect your user's account
Expand Down Expand Up @@ -121,7 +121,7 @@ After generating a token in the [step above](#generate-a-short-lived-token), you
<Callout type="info">
Make sure to add the `app` parameter to the end of the URL to specify the app.

Check out the [full API docs](/connect/api/#create-a-new-token) for all parameters you can pass when creating tokens, including setting redirect URLs for success or error cases.
Check out the [full API docs](/connect/api/#create-token) for all parameters you can pass when creating tokens, including setting redirect URLs for success or error cases.
</Callout>

### Make authenticated requests
Expand Down
4 changes: 2 additions & 2 deletions docs-v2/pages/connect/managed-auth/tokens.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Connect tokens currently have a 4-hour expiry, and can only be used once.

## Creating a token

See docs on [the `/tokens` endpoint](/connect/api/#create-a-new-token) to create new tokens.
See docs on [the `/tokens` endpoint](/connect/api/#create-token) to create new tokens.

## Webhooks

Expand All @@ -27,6 +27,6 @@ When you generate a token, you can specify a `webhook_uri` where Pipedream will

## Tokens are scoped to end users and environments

When you [create a new Connect token](/connect/api/#create-a-new-token), you pass an `external_user_id` and an `environment`. See the docs on [environments](/connect/environments/) for more information on passing environment in the SDK and API.
When you [create a new Connect token](/connect/api/#create-token), you pass an `external_user_id` and an `environment`. See the docs on [environments](/connect/environments/) for more information on passing environment in the SDK and API.

Tokens are scoped to this user and environment. When the user successfully connects an account with that token, it will be saved for that `external_user_id` in the specified environment.
2 changes: 1 addition & 1 deletion docs-v2/pages/connect/managed-auth/users.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ curl -X DELETE "https://api.pipedream.com/v1/connect/{project_id}/users/{externa
-H "Authorization: Bearer {access_token}"
```

For complete API details including TypeScript and Node.js examples, see the [API reference](/connect/api/#delete-an-end-user).
For complete API details including TypeScript and Node.js examples, see the [API reference](/connect/api/#delete-end-user).
2 changes: 1 addition & 1 deletion docs-v2/pages/connect/managed-auth/webhooks.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Connect Webhooks

When you [generate a Connect token](/connect/managed-auth/quickstart/#generate-a-short-lived-token), you can pass a `webhook_uri` parameter. Pipedream will send a POST request to this URL when the user completes the connection flow, or if an error occurs at any point. [See the API docs](/connect/api/#create-a-new-token) for details.
When you [generate a Connect token](/connect/managed-auth/quickstart/#generate-a-short-lived-token), you can pass a `webhook_uri` parameter. Pipedream will send a POST request to this URL when the user completes the connection flow, or if an error occurs at any point. [See the API docs](/connect/api/#create-token) for details.

## Webhook events

Expand Down
2 changes: 1 addition & 1 deletion docs-v2/pages/privacy-and-security/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Pipedream provides a [client-side SDK](/connect/api/#typescript-sdk-browser) to

When you initiate authorization, you must:

1. [Create a server-side token for a specific end user](/connect/api/#create-a-new-token)
1. [Create a server-side token for a specific end user](/connect/api/#create-token)
2. Initiate auth with that token, connecting an account for a specific user

These tokens can only initiate the auth connection flow. They have no permissions to access credentials or perform other operations against the REST API. They are meant to be scoped to a specific user, for use in clients that need to initiate auth flows.
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading