docusaurus-openapi icon indicating copy to clipboard operation
docusaurus-openapi copied to clipboard

could not proxy to https endpoint

Open jithinlalpr opened this issue 3 years ago • 15 comments

// @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?

jithinlalpr avatar Apr 11 '22 15:04 jithinlalpr

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

bourdakos1 avatar Apr 11 '22 17:04 bourdakos1

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

jithinlalpr avatar Apr 11 '22 17:04 jithinlalpr

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)

bourdakos1 avatar Apr 11 '22 17:04 bourdakos1

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

jithinlalpr avatar Apr 11 '22 17:04 jithinlalpr

If it’s built then it’s production

bourdakos1 avatar Apr 11 '22 18:04 bourdakos1

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?

jithinlalpr avatar Apr 12 '22 04:04 jithinlalpr

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

bourdakos1 avatar Apr 12 '22 04:04 bourdakos1

i have a cors enabled

jithinlalpr avatar Apr 12 '22 04:04 jithinlalpr

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?

jithinlalpr avatar Apr 12 '22 04:04 jithinlalpr

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

bourdakos1 avatar Apr 12 '22 05:04 bourdakos1

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

jithinlalpr avatar Apr 12 '22 05:04 jithinlalpr

Can you share your openapi spec?

bourdakos1 avatar Apr 12 '22 05:04 bourdakos1

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

  • url: http://localhost:3001/proxy

jithinlalpr avatar Apr 12 '22 05:04 jithinlalpr

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

bourdakos1 avatar Apr 12 '22 05:04 bourdakos1

remove proxy ?

jithinlalpr avatar Apr 12 '22 05:04 jithinlalpr