mirror of
https://github.com/ansible/awx.git
synced 2026-02-14 01:34:45 -03:30
test fixup
This commit is contained in:
11
src/api.js
11
src/api.js
@@ -1,5 +1,3 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const API_ROOT = '/api/';
|
||||
const API_LOGIN = `${API_ROOT}login/`;
|
||||
const API_LOGOUT = `${API_ROOT}logout/`;
|
||||
@@ -7,21 +5,14 @@ const API_V2 = `${API_ROOT}v2/`;
|
||||
const API_CONFIG = `${API_V2}config/`;
|
||||
const API_ORGANIZATIONS = `${API_V2}organizations/`;
|
||||
|
||||
const CSRF_COOKIE_NAME = 'csrftoken';
|
||||
const CSRF_HEADER_NAME = 'X-CSRFToken';
|
||||
const LOGIN_CONTENT_TYPE = 'application/x-www-form-urlencoded';
|
||||
|
||||
const defaultHttpAdapter = axios.create({
|
||||
xsrfCookieName: CSRF_COOKIE_NAME,
|
||||
xsrfHeaderName: CSRF_HEADER_NAME,
|
||||
});
|
||||
|
||||
class APIClient {
|
||||
static getCookie () {
|
||||
return document.cookie;
|
||||
}
|
||||
|
||||
constructor (httpAdapter = defaultHttpAdapter) {
|
||||
constructor (httpAdapter) {
|
||||
this.http = httpAdapter;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
import ReactDOM from 'react-dom';
|
||||
import {
|
||||
HashRouter,
|
||||
Redirect,
|
||||
@@ -48,15 +49,28 @@ import Users from './pages/Users';
|
||||
import ja from '../build/locales/ja/messages';
|
||||
import en from '../build/locales/en/messages';
|
||||
|
||||
const catalogs = { en, ja };
|
||||
//
|
||||
// Initialize http
|
||||
//
|
||||
|
||||
const http = axios.create({ xsrfCookieName: 'csrftoken', xsrfHeaderName: 'X-CSRFToken' });
|
||||
|
||||
//
|
||||
// Derive the language and region from global user agent data. Example: es-US
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator
|
||||
// see: https://developer.mozilla.org/en-US/docs/Web/API/Navigator
|
||||
//
|
||||
|
||||
const language = (navigator.languages && navigator.languages[0])
|
||||
|| navigator.language
|
||||
|| navigator.userLanguage;
|
||||
const languageWithoutRegionCode = language.toLowerCase().split(/[_-]+/)[0];
|
||||
const catalogs = { en, ja };
|
||||
|
||||
export async function main (api) {
|
||||
//
|
||||
// Function Main
|
||||
//
|
||||
|
||||
export async function main (render, api) {
|
||||
const el = document.getElementById('app');
|
||||
// fetch additional config from server
|
||||
const { data } = await api.getRoot();
|
||||
@@ -78,7 +92,7 @@ export async function main (api) {
|
||||
</Switch>
|
||||
);
|
||||
|
||||
render(
|
||||
return render(
|
||||
<HashRouter>
|
||||
<I18nProvider
|
||||
language={languageWithoutRegionCode}
|
||||
@@ -89,8 +103,8 @@ export async function main (api) {
|
||||
<Background>
|
||||
{!api.isAuthenticated() ? loginRoutes : (
|
||||
<Switch>
|
||||
<Route path="/login" render={() => <Redirect to="/home" />} />
|
||||
<Route exact path="/" render={() => <Redirect to="/home" />} />
|
||||
<Route path="/login" render={() => (<Redirect to="/home" />)} />
|
||||
<Route exact path="/" render={() => (<Redirect to="/home" />)} />
|
||||
<Route
|
||||
render={() => (
|
||||
<App
|
||||
@@ -266,4 +280,4 @@ export async function main (api) {
|
||||
</HashRouter>, el);
|
||||
};
|
||||
|
||||
export default main(new APIClient());
|
||||
main(ReactDOM.render, new APIClient(http));
|
||||
|
||||
Reference in New Issue
Block a user