NextPress proxy middleware for routing WordPress assets and content through your Next.js application
When usingNextPress is enabled during configuration, a proxy middleware file is generated that routes WordPress asset requests through your Next.js application. This allows the storefront to serve WordPress-managed CSS, JavaScript, and REST API responses alongside the Next.js frontend.
Condition: usingNextPress = true
Source: <nextpress>/proxy.ts (generated into your src/ directory)
The proxy middleware handles two types of requests:
Requests matching NextPress proxy patterns are forwarded to the WordPress backend through the @axistaylor/nextpress proxyByWCR function. These routes include:
| Pattern | Purpose |
|---|---|
/atx/:instance/proxiee | General proxy endpoint |
/atx/:instance/wp | WordPress core assets |
/atx/:instance/wc | WooCommerce assets |
/atx/:instance/wp-internal-assets/:path* | Internal WordPress assets |
/atx/:instance/wp-assets/:path* | Public WordPress assets |
/atx/:instance/wp-json/:path* | WordPress REST API |
These requests are also wrapped with withMiddlewareTokenManager to attach session credentials to proxied requests.
All other routes (non-asset, non-API) go through a setUriHeader function that adds an x-uri header to the request. This header tells the layout which WordPress page assets (scripts and stylesheets) to fetch and render.
The middleware applies to two groups of routes:
export const config = { matcher: [ // NextPress proxy routes '/atx/:instance/proxiee', '/atx/:instance/wp', '/atx/:instance/wc', '/atx/:instance/wp-internal-assets/:path*', '/atx/:instance/wp-assets/:path*', '/atx/:instance/wp-json/:path*', // All page routes (excludes _next, api, static files) '/((?!_next|api|favicon.ico|sw.js|\\.well-known|.*\\.).*)', ], };
| Package | Purpose |
|---|---|
@axistaylor/nextpress | Provides proxyByWCR and isProxiedRoute |
The proxy template depends on these internal modules:
| Import | Purpose |
|---|---|
@auth/withMiddlewareTokenManager | Wraps middleware to attach session tokens |
@auth/TokenManager | Token management utilities |
@utils/session-header | Session header name and value formatting |
When NextPress is enabled, the GraphQL client also generates additional helper functions for fetching WordPress content:
fetchAssetsByUri(uri) - Fetches enqueued scripts and stylesheets for a given page URIfetchPageWithSession(uri) - Fetches WordPress page content with session cookiesfetchCartPage() / fetchCheckoutPage() - Convenience wrappers for cart and checkout pagesfetchOrder(orderId, key) - Fetches order details