mirror of
https://github.com/mvvasilev/paste-eater.git
synced 2025-04-18 21:09:52 +03:00
Switch api location based on development or production environment
This commit is contained in:
parent
3b94fa4ea8
commit
92641274c3
3 changed files with 12 additions and 4 deletions
|
@ -27,4 +27,12 @@ function Layout({children}) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function apiLocation() {
|
||||||
|
if (process.env.NODE_ENV === "development") {
|
||||||
|
return "http://localhost:8000";
|
||||||
|
}
|
||||||
|
|
||||||
|
return window.location.origin;
|
||||||
|
}
|
||||||
|
|
||||||
export default Layout;
|
export default Layout;
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import Layout from "../Layout";
|
import Layout, { apiLocation } from "../Layout";
|
||||||
import Topbar from "../components/Topbar";
|
import Topbar from "../components/Topbar";
|
||||||
import MonacoEditor from 'react-monaco-editor';
|
import MonacoEditor from 'react-monaco-editor';
|
||||||
import fetchEditorThemes from '../EditorThemes';
|
import fetchEditorThemes from '../EditorThemes';
|
||||||
|
@ -62,7 +62,7 @@ export default function HomePage() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let promise = fetch(`${window.location.origin}/api/paste`, {
|
let promise = fetch(`${apiLocation()}/api/paste`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(paste)
|
body: JSON.stringify(paste)
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import Layout from "../Layout";
|
import Layout, { apiLocation } from "../Layout";
|
||||||
import Topbar from "../components/Topbar";
|
import Topbar from "../components/Topbar";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import MonacoEditor from 'react-monaco-editor';
|
import MonacoEditor from 'react-monaco-editor';
|
||||||
|
@ -18,7 +18,7 @@ export default function PastePage() {
|
||||||
let [ editor, setEditor ] = useState({});
|
let [ editor, setEditor ] = useState({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`${window.location.origin}/api/paste/${pasteId}`)
|
fetch(`${apiLocation()}/api/paste/${pasteId}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
Loading…
Add table
Reference in a new issue