0

I'm trying to make a proxy out of the nextjs api, but it seems like it doesn't work.

My pages/api/index.js looks like this:

import { NextApiRequest, NextApiResponse } from 'next';
import httpProxyMiddleware from 'next-http-proxy-middleware';

const API_SERVICE_URL = "https://api.company.io/";

export default (req: NextApiRequest, res: NextApiResponse) => {
  console.log('api', req, res)
  return httpProxyMiddleware(req, res, {
    target: API_SERVICE_URL
  })
}

I've the feeling it doesn't reach this, because the log never shows. So, I've moved it to pages/api/[...all] but this doesn't change anything. Anyone know how to use the Nextjs api to make a proxy?

Janessa Labeur
  • 119
  • 1
  • 11

1 Answers1

3

For reference purposes I will answer the question myself

I changed the file name from index.js to [...all] this way the middleware responds to all api calls instead of just https://localhost:8000/api

Janessa Labeur
  • 119
  • 1
  • 11