#Proxy /api to a different service?
3 messages · Page 1 of 1 (latest)
Hi @amber dune. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, you can set up Astro to proxy API requests to a different service running on another port. This can be achieved using the server.proxy option in your Astro configuration file.
Here's how you can configure Astro to proxy requests from /api to your API service running on port 3000:
import { defineConfig } from 'astro/config';
export default defineConfig({
server: {
proxy: {
'/api': '<http://localhost:3000',>
},
},
});
This configuration tells Astro to forward any requests that start with /api to <http://localhost:3000.> So, if you make a request to <http://your-astro-site.com/api/some-endpoint,> it will be proxied to <http://localhost:3000/api/some-endpoint.>
Remember to adjust the port number if your API service is running on a different port.
This feature is particularly useful during development when you're running your API service separately from your Astro site. It allows you to work on both your frontend and backend simultaneously without having to deal with CORS issues.