Created envars and updated config flow

This commit is contained in:
Dunemask 2021-08-14 17:56:29 -06:00
parent 0e424ec5fa
commit d4b5a555b9
12 changed files with 56 additions and 62 deletions

2
.env Normal file
View file

@ -0,0 +1,2 @@
PORT=52026
REACT_APP_CAIRO_URL=https://cairo.dunestorm.net

1
.env.local Normal file
View file

@ -0,0 +1 @@
REACT_APP_CAIRO_URL=http://localhost:52000

View file

@ -24,10 +24,11 @@
"sass": "^1.37.5"
},
"scripts": {
"start": "node server/main.js",
"start:dev": "nodemon server/main.js",
"start:react": "PORT=52026 react-scripts start",
"build": "react-scripts build"
"start": "node server/index.js",
"start:dev": "nodemon server/index.js",
"start:react": "react-scripts start",
"build:react": "react-scripts build",
"build:all": "npm run build:react && docker-compose build"
},
"eslintConfig": {
"extends": [

View file

@ -5,6 +5,6 @@ const cairoUrl = process.env.CAIRO_URL || "http://cairo.dunestorm.net:52000";
const nubianUrl = process.env.NUBIAN_URL || "http://nubian.dunestorm.net:52001";
const app = express();
app.use("/", express.static("build"));
app.use("/api/cairo", createProxyMiddleware({ target: cairoUrl }));
app.use("/api/nubian", createProxyMiddleware({ target: nubianUrl }));
app.use("/cairo", createProxyMiddleware({ target: cairoUrl }));
app.use("/nubian", createProxyMiddleware({ target: nubianUrl }));
app.listen(port, () => console.log(`🌴 Nile server started on ${port}! 🌴`));

View file

@ -8,9 +8,7 @@ import StashBoard from "./stash/StashBoard";
import { api } from "./config.json";
const getCairoApiInstance = (cairoAuthToken) =>
axios.create({
headers: { Authorization: `Bearer ${cairoAuthToken}` },
});
axios.create({ headers: { Authorization: `Bearer ${cairoAuthToken}` } });
class Stash extends React.Component {
constructor(props) {
@ -28,13 +26,17 @@ class Stash extends React.Component {
verifyLocalToken() {
const token = localStorage.getItem("cairoAuthToken");
axios
.get(api.cairo.verify, { headers: { authorization: `Bearer ${token}` } })
.get(api.cairo.urls.verify, {
headers: { authorization: `Bearer ${token}` },
})
.then(() => this.setState({ cairoApi: getCairoApiInstance(token) }))
.catch(() =>
window.location.replace(
`${api.cairo.login}?redirectUri=${window.location.href}`
)
.catch((error) => {
if (error.response && error.response.status === 401)
return window.location.replace(
`${process.env.REACT_APP_CAIRO_URL}${api.cairo.urls.login}?redirectUri=${window.location.href}`
);
console.error("Auth server not up/configured properly!");
});
}
setLocalToken(cairoAuthToken) {

View file

@ -1,8 +1,22 @@
{
"api": {
"cairo": {
"verify": "/api/cairo/user/data",
"login": "http://cairo.dunestorm.net:52000/login"
"urls": {
"verify": "/cairo/api/user/data",
"login": "/cairo/login"
}
},
"nubian": {
"urls": {
"files": "/nubian/api/stash/files",
"upload": "/nubian/api/stash/upload",
"download": "/nubian/api/stash/download",
"delete": "/nubian/api/stash/delete",
"public": "/nubian/api/stash/public"
},
"misc": {
"uploadField": "user-selected-file"
}
}
}
}

View file

@ -3,6 +3,6 @@ const cairoUrl = process.env.CAIRO_URL || "http://cairo.dunestorm.net:52000";
const nubianUrl = process.env.NUBIAN_URL || "http://nubian.dunestorm.net:52001";
module.exports = (app) => {
// Cairo Proxy
app.use("/api/cairo", createProxyMiddleware({ target: cairoUrl }));
app.use("/api/nubian", createProxyMiddleware({ target: nubianUrl }));
app.use("/cairo", createProxyMiddleware({ target: cairoUrl }));
app.use("/nubian", createProxyMiddleware({ target: nubianUrl }));
};

View file

@ -5,12 +5,9 @@ import { toast } from "react-toastify";
import Stashbar from "./Stashbar";
import StashUpload from "./StashUpload";
import StashContextMenu from "./StashContextMenu";
import { serverUrls } from "./api.json";
import { api } from "../config.json";
import "./scss/Stash.scss";
// Constants
const filesUrl = `${serverUrls.GET.filesUrl}`;
//Class
const buildFilebox = (file, index) => ({
file,
selected: false,
@ -37,7 +34,7 @@ class StashBoard extends React.Component {
componentDidMount() {
window.cairoApi
.get(filesUrl)
.get(api.nubian.urls.files)
.then((res) => {
if (res.data === undefined || res.data.length === undefined)
return toast.error("Error Loading Files");

View file

@ -11,11 +11,11 @@ import {
} from "@fortawesome/free-solid-svg-icons";
//Local Imports
import "./scss/stash/StashContextMenu.scss";
import { serverUrls } from "./api.json";
import { api } from "../config.json";
//Constants
const downloadUrl = `${serverUrls.POST.downloadUrl}`;
const deleteUrl = `${serverUrls.POST.deleteUrl}`;
const publicUrl = `${serverUrls.POST.publicUrl}`;
const downloadUrl = api.nubian.urls.download;
const deleteUrl = api.nubian.urls.delete;
const publicUrl = api.nubian.urls.public;
export default class StashContextMenu extends React.Component {
infoView() {

View file

@ -1,7 +1,6 @@
import React from "react";
import Dropzone from "react-dropzone";
import FileDisplay from "./FileDisplay";
import "./scss/stash/StashDropzone.scss";
class StashDropzone extends React.Component {
render() {

View file

@ -6,9 +6,9 @@ import { toast } from "react-toastify";
import StashDropzone from "./StashDropzone";
import StashUploadDialog from "./uploader/StashUploadDialog";
// Constants
import { serverUrls, serverFields } from "./api.json";
const uploadUrl = `${serverUrls.POST.uploadUrl}`;
const uploadField = serverFields.uploadField;
import { api } from "../config.json";
const uploadUrl = api.nubian.urls.upload;
const uploadField = api.nubian.misc.uploadField;
const cancelMessage = "User Canceled";
const successClearTime = 200;

View file

@ -1,22 +0,0 @@
{
"serverUrls": {
"POST": {
"uploadUrl": "/api/nubian/stash/upload",
"downloadUrl": "/api/nubian/stash/download",
"deleteUrl": "/api/nubian/stash/delete",
"publicUrl": "/api/nubian/stash/public"
},
"GET": {
"filesUrl": "/api/nubian/stash/files",
"rawUrl": "/api/nubian/stash/raw"
},
"api": {
"cairo": {
"verify": "/api/cairo/user/data"
}
}
},
"serverFields": {
"uploadField": "user-selected-file"
}
}