
import { getToken } from './token'

export default function request (url, options = {}) {
  const headers = new Headers();
  headers.append('Content-Type', 'application/json;charset=utf8');
  headers.append('X-Authorization-JWT', getToken());

  Object.keys(options.headers || {}).forEach(key => headers.append(key, options.headers[key]))

  return fetch(url, {...options, headers })
    .then(response => response.json())
    .then(data => {
      if (data.code === 1000) return data.data
      return Promise.reject(data.message)
    })
}

export const baseURL = process.env.NODE_ENV === 'development' ?
  '/api/wx' :
  '/api/wx'
