Using custom Frontend api with Strapi Backend

System Information
  • Strapi Version: 4.19.0
  • Operating System: Windows
  • Database: SqLite
  • Node Version: 20.11.13
  • NPM Version: >=6.0.0
  • Yarn Version: None


I’m quite new to this but i’ve put together a website with next.js as my frontend and a strapi csm for my backend. Right now i have a problem with basic authenication in my frontend application to use a “development-wall”. To this I’ve configured a basic middleware in my frontend which redirects to a page called hostname/password-redirect if not authorized, this in turn calls on host/api/password-redirect and redirects to hostname if password is correct. Problem is that this works well on the same domain in development on localhost:3000 and localhost:1337 but conflicts with two domains in production.

As i’ve configured strapi on a different domain (api.hostname) all routing to hostname/api redirects to api.hostname, and therefore api.hostname/password-redirect is used and doesnt work since the api is configured in the next.js frontend. I’m hosting on traditional shared server with two domains.

My network tab even sees that it always call on host/api/password-redirect first and then redirects on
api.hostname/password-redirect which results in an error not found.

I’ve looked at CORS for both frontend and backend and even shut down my backend to test why it does this but my question is if there a way to handle custom api’s in strapi? As i’ve previously said, i’m quite new to this.

Thank you if you have any idea how to fix this! :slight_smile: Otherwise i’ll probably try authentication with strapi even if that’s sort of an overkill if i only want simple password-redirect functionality.

Jesus christ. It was only a reroute that was set inside the hosting provider that set hostname/api to api.hostname. SOLVED!

i like answer