Server Routes Differences with PWA Kit

PWA Kit server routes are typically centralized as Express handlers in SSR server code. Storefront Next replaces that with file-based resource routes and loader/action handlers using standard Web Request/Response APIs. This distributes server behavior across route modules and aligns API endpoints with routing conventions.

Key Differences 

AspectPWA KitStorefront Next
PatternExpress routes in ssr.jsFile-based resource routes
ConfigurationCentralized in one fileDistributed across route files
Request APIExpress req/res objectsWeb Standard Request/Response
Route Definitionapp.get('/path', handler)Export loader/action from file
Dynamic RoutesExpress params (/:param)File naming ($param)
MiddlewareExpress middleware chainReact Router middleware exports
Client ExecutionServer onlyOptional clientLoader/clientAction

PWA Kit Express Routes 

1// Single file: app/ssr.js
2app.get("/api/search", async (req, res) => {
3  const query = req.query.q;
4  const results = await searchProducts(query);
5  res.json(results);
6});
7
8app.post("/api/auth/login", async (req, res) => {
9  const { email, password } = req.body;
10  const session = await login(email, password);
11  res.json(session);
12});

Storefront Next Resource Routes 

1// src/routes/resource.search.ts
2export function loader({ request }: LoaderFunctionArgs) {
3  const url = new URL(request.url);
4  const query = url.searchParams.get("q");
5  const results = await searchProducts(query);
6  return Response.json(results);
7}
8
9// src/routes/resource.auth.login.ts
10export async function action({ request }: ActionFunctionArgs) {
11  const { email, password } = await request.json();
12  const session = await login(email, password);
13  return Response.json(session);
14}

Key Similarities 

  • Both support GET (loaders) and POST/PUT/DELETE (actions).
  • Both can set cache headers and response status codes.
  • Both integrate with SLAS for authentication callbacks.
  • Both can proxy Commerce API calls.
  • Both support dynamic route parameters.

Storefront Conversion Considerations 

Keep these tips in mind when you convert your PWA Kit storefront to Storefront Next.

  • Route extraction: Move logic from ssr.js callbacks into separate route files.
  • Request handling: Convert Express req.body/req.query to request.json()/URL.searchParams.
  • Response handling: Convert res.json() to Response.json().
  • Middleware: Use React Router middleware exports instead of Express middleware.
  • Client-side option: Consider adding clientLoader for endpoints that can run on the client.