Skip to content
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

API rewrites not working #848

Closed
LucasBassetti opened this issue Dec 17, 2020 · 5 comments
Closed

API rewrites not working #848

LucasBassetti opened this issue Dec 17, 2020 · 5 comments

Comments

@LucasBassetti
Copy link

LucasBassetti commented Dec 17, 2020

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

  • OS/Environment: MacOS Catalina 10.15.7
  • @sls-next/serverless-component version: 1.19.0-alpha.21
  • Next.js version: 10.0.3

Additional context

I tried this but didn't work

@dphang
Copy link
Collaborator

dphang commented Dec 17, 2020

Yeah, unfortunately this is a cross-lambda rewrite, so this won't work since the default Lambda (the /sitemap.xml path) doesn't have the API code, so only redirects will work =(. By design, the default lambda and API lambda are distinct, to reduce code size.

You could try doing an external rewrite as a workaround (point to https://domain.com/api/sitemap), or fork the package and combine the handlers (though it will be quite some refactoring). Note that external rewrites are only available in the latest 1.19 alpha version.

@LucasBassetti
Copy link
Author

Thanks @dphang !! Are you intend to add this in the future?

@dphang
Copy link
Collaborator

dphang commented Dec 18, 2020

Not sure as it will involve some fundamental changes of the architecture, @danielcondemarin any thoughts on this?

@danielcondemarin
Copy link
Contributor

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.

@LucasBassetti
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants