digitros / nextjs-fastapi

https://nextjs-fastapi-starter.vercel.app
MIT License
408 stars 117 forks source link

Swagger UI #3

Closed riziles closed 1 year ago

riziles commented 1 year ago

Thanks for the great template! I've been playing around with trying to get the Swagger UI to work. I found that if I make the following tweaks to next.config.js then I can see them in dev. Haven't tried deploying to Vercel yet. Curious to know if you see any issues with this approach?

/** @type {import('next').NextConfig} */
const nextConfig = {
  rewrites: async () => {
    return [
      {
        source: "/api/:path*",
        destination:
          process.env.NODE_ENV === "development"
            ? "http://127.0.0.1:8000/api/:path*"
            : "/api/",
      },
      {
        source: "/docs",
        destination:
          process.env.NODE_ENV === "development"
            ? "http://127.0.0.1:8000/docs"
            : "/api/docs",
      },
      {
        source: "/openapi.json",
        destination:
          process.env.NODE_ENV === "development"
            ? "http://127.0.0.1:8000/openapi.json"
            : "/api/openapi.json",
      },
    ];
  },
};

module.exports = nextConfig;
mccombs commented 1 year ago

Worked like a charm for me!

digitros commented 1 year ago

Thanks for the great template! I've been playing around with trying to get the Swagger UI to work. I found that if I make the following tweaks to next.config.js then I can see them in dev. Haven't tried deploying to Vercel yet. Curious to know if you see any issues with this approach?


/** @type {import('next').NextConfig} */

const nextConfig = {

  rewrites: async () => {

    return [

      {

        source: "/api/:path*",

        destination:

          process.env.NODE_ENV === "development"

            ? "http://127.0.0.1:8000/api/:path*"

            : "/api/",

      },

      {

        source: "/docs",

        destination:

          process.env.NODE_ENV === "development"

            ? "http://127.0.0.1:8000/docs"

            : "/api/docs",

      },

      {

        source: "/openapi.json",

        destination:

          process.env.NODE_ENV === "development"

            ? "http://127.0.0.1:8000/openapi.json"

            : "/api/openapi.json",

      },

    ];

  },

};

module.exports = nextConfig;

Looks really great. I don't see any problem for this.