// @flow

import qs from 'query-string'

let root: string

export function setApiRoot(url: string) {
	root = url
}

export const API = (path: string, query: ?Object = null) => {
	if (process.env.NODE_ENV !== 'production') {
		if (!path.startsWith('/')) {
			throw new Error('invalid path requested from the api!')
		}
	}

	let url = root + path

	if (query) {
		url += `?${qs.stringify(query)}`
	}

	return url
}

// @flow

import qs from 'query-string'

import {IS_PRODUCTION} from '@frogpond/constants'

let root: string

export function setApiRoot(url: string) {
	root = url
}

export const API = (path: string, query: ?Object = null) => {
	if (!IS_PRODUCTION) {
		if (!path.startsWith('/')) {
			throw new Error('invalid path requested from the api!')
		}
	}

	let url = root + path

	if (query) {
		url += `?${qs.stringify(query)}`
	}

	return url
}

Use IS_PRODUCTION instead of duplicate logic
API: Use IS_PRODUCTION instead of duplicate logic

Signed-off-by: Kristofer Rye <1ed31cfd0b53bc3d1689a6fee6dbfc9507dffd22@gmail.com>
