Merge pull request #4570 from influxdata/cors-fix
Handle cors feed request with fetch apipull/4571/head
commit
79efa8bb0a
|
@ -8,7 +8,6 @@ import {notify} from 'src/shared/actions/notifications'
|
||||||
import {notifyJSONFeedFailed} from 'src/shared/copy/notifications'
|
import {notifyJSONFeedFailed} from 'src/shared/copy/notifications'
|
||||||
|
|
||||||
import {JSONFeedData} from 'src/types'
|
import {JSONFeedData} from 'src/types'
|
||||||
import {AxiosResponse} from 'axios'
|
|
||||||
|
|
||||||
export enum ActionTypes {
|
export enum ActionTypes {
|
||||||
FETCH_JSON_FEED_REQUESTED = 'FETCH_JSON_FEED_REQUESTED',
|
FETCH_JSON_FEED_REQUESTED = 'FETCH_JSON_FEED_REQUESTED',
|
||||||
|
@ -54,7 +53,7 @@ export const fetchJSONFeedAsync = (url: string) => async (
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
dispatch(fetchJSONFeedRequested())
|
dispatch(fetchJSONFeedRequested())
|
||||||
try {
|
try {
|
||||||
const {data} = (await fetchJSONFeedAJAX(url)) as AxiosResponse<JSONFeedData>
|
const data = (await fetchJSONFeedAJAX(url)) as JSONFeedData
|
||||||
// data could be from a webpage, and thus would be HTML
|
// data could be from a webpage, and thus would be HTML
|
||||||
if (typeof data === 'string' || !data) {
|
if (typeof data === 'string' || !data) {
|
||||||
dispatch(fetchJSONFeedFailed())
|
dispatch(fetchJSONFeedFailed())
|
||||||
|
|
|
@ -1,16 +1,8 @@
|
||||||
import AJAX from 'src/utils/ajax'
|
export const fetchJSONFeed = async (url: string) => {
|
||||||
import {JSONFeedData} from 'src/types'
|
const response = await fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
mode: 'cors',
|
||||||
|
})
|
||||||
|
|
||||||
const excludeBasepath = true // don't prefix route of external link with basepath/
|
return response.json()
|
||||||
|
}
|
||||||
export const fetchJSONFeed = (url: string) =>
|
|
||||||
AJAX<JSONFeedData>(
|
|
||||||
{
|
|
||||||
method: 'GET',
|
|
||||||
url,
|
|
||||||
// For explanation of why this header makes this work:
|
|
||||||
// https://stackoverflow.com/questions/22968406/how-to-skip-the-options-preflight-request-in-angularjs
|
|
||||||
headers: {'Content-Type': 'text/plain; charset=UTF-8'},
|
|
||||||
},
|
|
||||||
excludeBasepath // don't prefix route of external link with basepath
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue