cloud-annotations / docusaurus-openapi

🦕 OpenAPI plugin for generating API reference docs in Docusaurus v2.
https://docusaurus-openapi.netlify.app
MIT License
493 stars 82 forks source link

could not proxy to https endpoint #176

Open jithinlalpr opened 2 years ago

jithinlalpr commented 2 years ago
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

const lightCodeTheme = require('prism-react-renderer/themes/duotoneLight');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');

/** @type {import('@docusaurus/types').Config} */
const config = {
    title: 'TITLE',
    tagline: 'The next build portal',
    url: 'https://title.com',
    baseUrl: '/',
    onBrokenLinks: 'throw',
    onBrokenMarkdownLinks: 'warn',
    favicon: 'img/favicon.ico',
    organizationName: 'facebook', // Usually your GitHub org/user name.
    projectName: 'title', // Usually your repo name.

    plugins: [
        [
            'docusaurus-plugin-openapi',
            {
                id: 'core',
                path: 'openapi.json',
                routeBasePath: '/api/1.0/dev',
            },
        ],
    ],
    presets: [
        [
            'docusaurus-preset-openapi',
            /** @type {import('docusaurus-preset-openapi').Options} */
            ({
                api: {
                    path: 'openapi.json',
                },
                theme: {
                    customCss: require.resolve('./src/css/custom.css'),
                },
                proxy: {
                    '/': {
                        target: 'https://qa.title.com/api/1.0/dev',
                    },
                },
            }),
        ],
    ],

    themeConfig:
        /** @type {import('docusaurus-preset-openapi').ThemeConfig} */
        ({
            colorMode: {
                disableSwitch: true,
                defaultMode: 'light',
            },
            navbar: {
                title: 'Title',
                logo: {
                    alt: 'My Site Logo',
                    src: 'img/logo.svg',
                },
                items: [{ to: '/api', label: 'API', position: 'left' }],
            },
            prism: {
                theme: lightCodeTheme,
                darkTheme: darkCodeTheme,
            },
        }),
};

module.exports = config;

IS there anything that i am missing or doing wrong?

bourdakos1 commented 2 years ago

Looks okay to me, is there an error message or anything?

jithinlalpr commented 2 years ago

none, i am getting back the index,html file of the front end docusaurus site

localhost is working fine, i could proxy it, but not the https once i hosted it on firebase

bourdakos1 commented 2 years ago

Oh, was the Docusaurus site running in dev mode or a production build? (The proxy only works in dev mode, because it’s via webpack dev server)

jithinlalpr commented 2 years ago

how do i check that? i build it deployed it to firebase

bourdakos1 commented 2 years ago

If it’s built then it’s production

jithinlalpr commented 2 years ago

how do i proxy on the prod or on the dev ? i hosted my api on a https domain, now can i proxy request from the local machine?

bourdakos1 commented 2 years ago

If you set up CORS you shouldn’t need a proxy. If that isn’t an option you would need some sort of server to forward requests to the api

jithinlalpr commented 2 years ago

i have a cors enabled

jithinlalpr commented 2 years ago

can i put the build folder as a public asset and point that as my docusaurus? if so then what should i do about the proxy?

bourdakos1 commented 2 years ago

Yes, the build folder is intended to be the public assets. If CORS is enabled, you shouldn’t need a proxy, you can use the api url as the host and the request will go directly to it

jithinlalpr commented 2 years ago

can you give me a sample config file for that? right now i am missing something and i am not able to send requests to the live api domain from a deployed docusaurus site which is another domain

bourdakos1 commented 2 years ago

Can you share your openapi spec?

jithinlalpr commented 2 years ago

openapi: 3.0.0 info: version: "" title: title paths: { } servers:

bourdakos1 commented 2 years ago

Change url to https://qa.title.com/api/1.0/dev

jithinlalpr commented 2 years ago

remove proxy ?