Code below. I console.log the following error via Components/Pages/Scrap.tsx.
{status: 'PARSING_ERROR', originalStatus: 200, data: '<!DOCTYPE html>\n<html lang="en">\n <head>\n <met…uild` or `yarn build`.\n -->\n </body>\n</html>\n', error: `SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON`}
data: "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <link rel=\"icon\" href=\"/favicon.ico\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <meta name=\"theme-color\" content=\"#000000\" />\n <meta\n name=\"description\"\n content=\"Web site created using create-react-app\"\n />\n <link rel=\"apple-touch-icon\" href=\"/logo192.png\" />\n <!--\n manifest.json provides metadata used when your web app is installed on a\n user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/\n -->\n <link rel=\"manifest\" href=\"/manifest.json\" />\n <!--\n Notice the use of in the tags above.\n It will be replaced with the URL of the `public` folder during the build.\n Only files inside the `public` folder can be referenced from the HTML.\n\n Unlike \"/favicon.ico\" or \"favicon.ico\", \"/favicon.ico\" will\n work correctly both with client-side routing and a non-root public URL.\n Learn how to configure a non-root public URL by running `npm run build`.\n -->\n <title>React App</title>\n <script defer src=\"/static/js/bundle.js\"></script></head>\n <body>\n <noscript>You need to enable JavaScript to run this app.</noscript>\n <div id=\"root\"></div>\n <!--\n This HTML file is a template.\n If you open it directly in the browser, you will see an empty page.\n\n You can add webfonts, meta tags, or analytics to this file.\n The build step will place the bundled scripts into the <body> tag.\n\n To begin the development, run `npm start` or `yarn start`.\n To create a production bundle, use `npm run build` or `yarn build`.\n -->\n </body>\n</html>\n"
error: "SyntaxError: Unexpected token '<', \"<!DOCTYPE \"... is not valid JSON"
originalStatus: 200
status: "PARSING_ERROR"
[[Prototype]]: Object
some investigation revealed in the network tab of dev tools that RTK query seems to be trying to query http://localhost:3000/scrape?url=https://somewebsite.com instead of the expected endpoint of https://localhost:7125/scrape?url=https://somewebsite.com
api/scrape-api.ts
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import type { scrapeModel } from '../models/scrape-model';
export const scrapeApi = createApi({
reducerPath: 'scrapeApi',
baseQuery: fetchBaseQuery({ baseUrl: 'https://localhost:7125/' }),
endpoints: builder => ({
scrapeUrl: builder.query<scrapeModel, string>({
query: url => `scrape?url=${url}`
})
})
});
export const { useScrapeUrlQuery } = scrapeApi;
store/index.ts
import { configureStore } from '@reduxjs/toolkit';
import { setupListeners } from '@reduxjs/toolkit/dist/query';
import { scrapeApi } from '../api/scrape-api';
import scrapeReducer from './scrape';
export const store = configureStore({
reducer: {
[scrapeApi.reducerPath]: scrapeApi.reducer,
scrape: scrapeReducer
},
middleware: getDefaultMiddleware => {
return getDefaultMiddleware().concat(scrapeApi.middleware);
}
});
setupListeners(store.dispatch);
export type RootState = ReturnType<typeof store.getState>;
Components/Pages/Scrap.tsx
import { useEffect } from 'react';
import { useScrapeUrlQuery } from '../../api/scrape-api';
const Scrape = () => {
const { data, error, isLoading } = useScrapeUrlQuery(
'https://somewebsite.com'
);
useEffect(() => {
if (error) {
console.log(error);
}
}, [data, error, isLoading]);
return (
<div>
<h1>I'm the scrape page</h1>
{isLoading && <div>Loading...</div>}
</div>
);
};
export default Scrape;