Skip to content

Commit

Permalink
update urls and cors (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
ostatni5 committed Oct 31, 2021
1 parent dbfc320 commit fddb894
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/WrapperApp/WrapperApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ThreeEditor from '../ThreeEditor/ThreeEditor';
import UserData from '../util/user/UserData';
import SimulationPanel from './components/SimulationPanel';
import { useStore } from '../services/StoreService';
import { DEMO_MODE } from '../util/Config';


interface TabPanelProps {
Expand Down Expand Up @@ -47,14 +48,13 @@ function WrapperApp() {
setTabsValue(newValue);
};

const demoMode = process.env.REACT_APP_TARGET === 'demo';

return (
<Box sx={{ width: '100%', height: '100vh', display: 'flex', flexDirection: 'column' }}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={tabsValue} onChange={handleChange} >
<Tab label="Editor" />
<Tab label="Run" disabled={demoMode} />
<Tab label="Run" disabled={DEMO_MODE} />
<Tab label="Results" disabled />
<Tab label="Projects" disabled />
<Tab label="About" />
Expand All @@ -64,7 +64,7 @@ function WrapperApp() {
<TabPanel value={tabsValue} index={0} >
<ThreeEditor onEditorInitialized={(editor) => editorRef.current = editor} />
</TabPanel>
{demoMode ||
{DEMO_MODE ||
<TabPanel value={tabsValue} index={1}>
<SimulationPanel />
</TabPanel>
Expand Down
9 changes: 6 additions & 3 deletions src/WrapperApp/components/SimulationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ky from 'ky';

import React, { useState } from "react";
import { useStore } from '../../services/StoreService';
import { BACKEND_URL } from '../../util/Config';
import { BACKEND_URL, CORS } from '../../util/Config';

interface SimulationPanelProps {
onError?: (error: unknown) => void;
Expand All @@ -16,10 +16,13 @@ export default function SimulationPanel(props: SimulationPanelProps) {

const sendRequest = () => {
setInProgress(true);
ky.post(`${BACKEND_URL}/sh/demo`, { json: editorRef.current?.toJSON() })
ky.post(`${BACKEND_URL}/sh/demo`, {
mode: CORS ? 'cors' : 'no-cors',
json: editorRef.current?.toJSON()
})
.json()
.then((response) => {
console.log(response);
alert(response);
props.onSuccess?.call(null, response);
})
.catch((error) => {
Expand Down
4 changes: 3 additions & 1 deletion src/util/Config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const BACKEND_URL = process.env.REACT_APP_BACKEND_URL ?? 'https://617d3fe41eadc50017136443.mockapi.io';
export const BACKEND_URL = process.env.REACT_APP_BACKEND_URL ?? 'http://localhost:5000';
export const CORS = false;
export const DEMO_MODE = process.env.REACT_APP_TARGET === 'demo';

0 comments on commit fddb894

Please sign in to comment.