mirror of
https://github.com/usatiuk/writer.git
synced 2025-10-29 00:17:48 +01:00
make use of env variables in frontend
This commit is contained in:
@@ -14,6 +14,7 @@ import { RouteComponentProps, withRouter } from "react-router";
|
|||||||
import { Dispatch } from "redux";
|
import { Dispatch } from "redux";
|
||||||
import { IDocumentJSON } from "~../../src/entity/Document";
|
import { IDocumentJSON } from "~../../src/entity/Document";
|
||||||
import { showDeletionToast, showSharedToast } from "~AppToaster";
|
import { showDeletionToast, showSharedToast } from "~AppToaster";
|
||||||
|
import { webRoot } from "~env";
|
||||||
import { LoadingStub } from "~LoadingStub";
|
import { LoadingStub } from "~LoadingStub";
|
||||||
import { NotFound } from "~NotFound";
|
import { NotFound } from "~NotFound";
|
||||||
import {
|
import {
|
||||||
@@ -176,7 +177,7 @@ export class DocumentEditComponent extends React.PureComponent<
|
|||||||
public copyLink() {
|
public copyLink() {
|
||||||
const doc = this.props.allDocs[this.state.id];
|
const doc = this.props.allDocs[this.state.id];
|
||||||
navigator.clipboard.writeText(
|
navigator.clipboard.writeText(
|
||||||
`http://localhost:1234/shared/${this.props.username}/${doc.id}`,
|
`http://${webRoot}/shared/${this.props.username}/${doc.id}`,
|
||||||
);
|
);
|
||||||
showSharedToast();
|
showSharedToast();
|
||||||
}
|
}
|
||||||
|
|||||||
2
frontend/src/env.ts
Normal file
2
frontend/src/env.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export const apiRoot = process.env.API_ROOT || "http://localhost:3000";
|
||||||
|
export const webRoot = process.env.WEB_ROOT || "http://localhost:1234";
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { apiRoot } from "~env";
|
||||||
|
|
||||||
let token: string | null;
|
let token: string | null;
|
||||||
|
|
||||||
export function setToken(_token: string) {
|
export function setToken(_token: string) {
|
||||||
@@ -12,8 +14,6 @@ export function deleteToken(_token: string) {
|
|||||||
token = null;
|
token = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const root = "http://localhost:3000";
|
|
||||||
|
|
||||||
export async function fetchJSON(
|
export async function fetchJSON(
|
||||||
path: string,
|
path: string,
|
||||||
method: string,
|
method: string,
|
||||||
@@ -23,7 +23,7 @@ export async function fetchJSON(
|
|||||||
if (typeof body === "object") {
|
if (typeof body === "object") {
|
||||||
body = JSON.stringify(body);
|
body = JSON.stringify(body);
|
||||||
}
|
}
|
||||||
const response = await fetch(root + path, {
|
const response = await fetch(apiRoot + path, {
|
||||||
method,
|
method,
|
||||||
body,
|
body,
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
Reference in New Issue
Block a user