question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API rewrites not working

See original GitHub issue

Describe the bug

Hi, I’m trying to implement api rewrites do my sitemap, but is not working.

Actual behavior

I have a rewrite config { source: '/sitemap.xml', destination: '/api/sitemap' },. /api/sitemap works but /sitemap.xml not

Expected behavior

/sitemap.xml working

Screenshots/Code/Logs

routes-manifest.json inside api-lambda

{"version":3,"pages404":true,"basePath":"","redirects":[{"source":"/:path+/","destination":"/:path+","statusCode":308,"regex":"^(?:/((?:[^/]+?)(?:/(?:[^/]+?))*))/$"}],"rewrites":[{"source":"/sitemap.xml","destination":"/api/sitemap","regex":"^/sitemap\\.xml$"},{"source":"/base/sitemap.xml","destination":"/api/base/sitemap","regex":"^/base/sitemap\\.xml$"},{"source":"/booking/sitemap.xml","destination":"/api/booking/sitemap","regex":"^/booking/sitemap\\.xml$"},{"source":"/blog/sitemap.xml","destination":"/api/blog/sitemap","regex":"^/blog/sitemap\\.xml$"},{"source":"/clinics/sitemap.xml","destination":"/api/clinics/sitemap","regex":"^/clinics/sitemap\\.xml$"},{"source":"/labs/sitemap.xml","destination":"/api/labs/sitemap","regex":"^/labs/sitemap\\.xml$"},{"source":"/pharmacies/sitemap.xml","destination":"/api/pharmacies/sitemap","regex":"^/pharmacies/sitemap\\.xml$"},{"source":"/prescriptions/sitemap.xml","destination":"/api/prescriptions/sitemap","regex":"^/prescriptions/sitemap\\.xml$"}],"headers":[],"dynamicRoutes":[{"page":"/blog/page/[page]","regex":"^/blog/page/([^/]+?)(?:/)?$","routeKeys":{"page":"page"},"namedRegex":"^/blog/page/(?<page>[^/]+?)(?:/)?$"},{"page":"/booking/[slug]","regex":"^/booking/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/booking/(?<slug>[^/]+?)(?:/)?$"},{"page":"/clinic/[slug]","regex":"^/clinic/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/clinic/(?<slug>[^/]+?)(?:/)?$"},{"page":"/lab/[slug]","regex":"^/lab/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/lab/(?<slug>[^/]+?)(?:/)?$"},{"page":"/lab-test/[slug]","regex":"^/lab\\-test/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/lab\\-test/(?<slug>[^/]+?)(?:/)?$"},{"page":"/pharmacy/[slug]","regex":"^/pharmacy/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/pharmacy/(?<slug>[^/]+?)(?:/)?$"},{"page":"/post/[slug]","regex":"^/post/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/post/(?<slug>[^/]+?)(?:/)?$"},{"page":"/post-category/[slug]","regex":"^/post\\-category/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/post\\-category/(?<slug>[^/]+?)(?:/)?$"},{"page":"/post-category/[slug]/page/[page]","regex":"^/post\\-category/([^/]+?)/page/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug","page":"page"},"namedRegex":"^/post\\-category/(?<slug>[^/]+?)/page/(?<page>[^/]+?)(?:/)?$"},{"page":"/post-tag/[slug]","regex":"^/post\\-tag/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/post\\-tag/(?<slug>[^/]+?)(?:/)?$"},{"page":"/post-tag/[slug]/page/[page]","regex":"^/post\\-tag/([^/]+?)/page/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug","page":"page"},"namedRegex":"^/post\\-tag/(?<slug>[^/]+?)/page/(?<page>[^/]+?)(?:/)?$"},{"page":"/prescription/[slug]","regex":"^/prescription/([^/]+?)(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^/prescription/(?<slug>[^/]+?)(?:/)?$"}],"dataRoutes":[{"page":"/blog","dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/blog.json$"},{"page":"/blog/page/[page]","routeKeys":{"page":"page"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/blog/page/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/blog/page/(?<page>[^/]+?)\\.json$"},{"page":"/booking/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/booking/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/booking/(?<slug>[^/]+?)\\.json$"},{"page":"/clinic/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/clinic/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/clinic/(?<slug>[^/]+?)\\.json$"},{"page":"/lab/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/lab/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/lab/(?<slug>[^/]+?)\\.json$"},{"page":"/lab-test/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/lab\\-test/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/lab\\-test/(?<slug>[^/]+?)\\.json$"},{"page":"/pharmacy/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/pharmacy/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/pharmacy/(?<slug>[^/]+?)\\.json$"},{"page":"/post/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post/(?<slug>[^/]+?)\\.json$"},{"page":"/post-category/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post\\-category/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post\\-category/(?<slug>[^/]+?)\\.json$"},{"page":"/post-category/[slug]/page/[page]","routeKeys":{"slug":"slug","page":"page"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post\\-category/([^/]+?)/page/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post\\-category/(?<slug>[^/]+?)/page/(?<page>[^/]+?)\\.json$"},{"page":"/post-tag/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post\\-tag/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post\\-tag/(?<slug>[^/]+?)\\.json$"},{"page":"/post-tag/[slug]/page/[page]","routeKeys":{"slug":"slug","page":"page"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post\\-tag/([^/]+?)/page/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/post\\-tag/(?<slug>[^/]+?)/page/(?<page>[^/]+?)\\.json$"},{"page":"/prescription/[slug]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/prescription/([^/]+?)\\.json$","namedDataRouteRegex":"^/_next/data/R9NH_4S9IelBrCTCk\\-1It/prescription/(?<slug>[^/]+?)\\.json$"}]}

Versions

Additional context

I tried this but didn’t work

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
LucasBassetticommented, Dec 21, 2020

Ok, for now it works with an external rewrite. Thanks!!

0reactions
danielcondemarincommented, Dec 19, 2020

I’d be inclined to say no given the considerable changes this would involve for arguably little benefit. Maybe in future once everything becomes more modular we will be able to provide an option to host everything in the same lambda, but that’s still far. For now I’ll close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rewrites not working in dev server client side navigation in ...
This worked perfectly in Next.js through 12.1 but now when I am testing out 12.2, client-side (SPA) navigation in the dev server is...
Read more >
Rewrites is not working for external root URL - next.js
This looks correct. It's most likely a browser cache setting, since you probably tried using redirects() it cached the redirect. Try opening ...
Read more >
Rewrites - next.config.js
Rewrites allow you to map an incoming request path to a different destination path. Rewrites act as a URL proxy and mask the...
Read more >
Next.js Rewrites Example - StackBlitz
Rewrites Example. This example shows how to use [rewrites in. Next.js](https://nextjs.org/docs/. api-reference/next.config.js/rewrites) to map.
Read more >
Next.js rewrites : r/Netlify - Reddit
I have a web app which uses a next front end and a separate api backend (The client was on react before the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found