mirror of
https://github.com/mvvasilev/paste-eater.git
synced 2025-04-11 18:05:01 +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;
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useState } from "react";
|
||||
import Layout from "../Layout";
|
||||
import Layout, { apiLocation } from "../Layout";
|
||||
import Topbar from "../components/Topbar";
|
||||
import MonacoEditor from 'react-monaco-editor';
|
||||
import fetchEditorThemes from '../EditorThemes';
|
||||
|
@ -62,7 +62,7 @@ export default function HomePage() {
|
|||
return;
|
||||
}
|
||||
|
||||
let promise = fetch(`${window.location.origin}/api/paste`, {
|
||||
let promise = fetch(`${apiLocation()}/api/paste`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(paste)
|
||||
}).then((response) => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
import Layout from "../Layout";
|
||||
import Layout, { apiLocation } from "../Layout";
|
||||
import Topbar from "../components/Topbar";
|
||||
import { useParams } from "react-router-dom";
|
||||
import MonacoEditor from 'react-monaco-editor';
|
||||
|
@ -18,7 +18,7 @@ export default function PastePage() {
|
|||
let [ editor, setEditor ] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`${window.location.origin}/api/paste/${pasteId}`)
|
||||
fetch(`${apiLocation()}/api/paste/${pasteId}`)
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
|
|
Loading…
Add table
Reference in a new issue