Skip to content

Commit

Permalink
Fixed getSignedUrl, improved watch
Browse files Browse the repository at this point in the history
  • Loading branch information
axelstudios committed Mar 17, 2023
1 parent aa9471b commit 26bab6d
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 31 deletions.
1 change: 0 additions & 1 deletion alfalfa_web/alfalfa.svg

This file was deleted.

2 changes: 1 addition & 1 deletion alfalfa_web/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const App = () => {
<ThemeProvider theme={theme}>
<LocalizationProvider dateAdapter={AdapterLuxon}>
<div className={styles.root}>
<AppBar position="static">
<AppBar position="static" sx={{ zIndex: 1 }}>
<Toolbar>
<Link to={"/"} className={styles.title} style={{ textDecoration: "none", color: "unset" }}>
<Typography variant="h5" color="inherit">
Expand Down
6 changes: 4 additions & 2 deletions alfalfa_web/app.js → alfalfa_web/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import "@fontsource/roboto";
import "normalize.css/normalize.css";
import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import { App } from "./components/App/App.js";
import { App } from "./App/App.js";

ReactDOM.render(
<BrowserRouter>
<App />
<React.StrictMode>
<App />
</React.StrictMode>
</BrowserRouter>,
document.getElementById("root")
);
5 changes: 1 addition & 4 deletions alfalfa_web/generate-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const openapiSpecification = swaggerJsdoc({
description:
"Alfalfa transforms Building Energy Models (BEMs) into virtual buildings by providing industry standard building control interfaces for interacting with models as they run",
"x-logo": {
url: "/assets/alfalfa.svg"
url: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTYgOTIuMzYzIj48cGF0aCBmaWxsPSIjODM5NGEwIiBkPSJNMzUuNDE4IDg3LjM2MWMuMDAyLTEyLjcyMS4wMTMtMzEuNTE5LS4wMDItNDQuMjQxIDUuMz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@@ -203,6 +203,3 @@ mkdirp.sync("build/app/assets");
fs.writeFileSync("build/app/openapi.json", JSON.stringify(openapiSpecification));

npmRun.execSync("redoc-cli build openapi.json -t ../../docs.hbs", { cwd: __dirname + "/build/app" });

fs.copyFileSync("alfalfa.svg", "build/app/assets/alfalfa.svg");
fs.renameSync("build/app/redoc-static.html", "build/app/docs.html");
28 changes: 28 additions & 0 deletions alfalfa_web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions alfalfa_web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"build-docs": "node ./generate-docs.js",
"build-server": "babel -d ./build ./server",
"clean": "npx rimraf build",
"start": "node ./build/index.js",
"start-dev": "npm run build-server && env-cmd -f ../.env npm start",
"watch": "nodemon -e js,html --ignore build/ --exec \"npm run build-app && npm run build-server && npm start\""
"start": "env-cmd -f ../.env node ./build/index.js",
"watch": "run-p watch-app watch-docs watch-server",
"watch-app": "webpack --watch",
"watch-docs": "supervisor -e js -w generate-docs.js,server/api-v2.js,server/api-haystack.js -n exit -t generate-docs.js",
"watch-server": "supervisor -e js -w server -x run-s -- build-server start"
},
"author": "",
"license": "ISC",
Expand Down Expand Up @@ -63,7 +65,6 @@
"html-webpack-plugin": "^5.5.0",
"mkdirp": "^2.1.3",
"node-sass": "^8.0.0",
"nodemon": "^2.0.20",
"npm-run": "^5.0.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.21",
Expand All @@ -75,6 +76,7 @@
"should": "^13.2.3",
"style-loader": "^3.3.1",
"supertest": "4.0.2",
"supervisor": "github:axelstudios/node-supervisor#4e4185b81a9724af26922a2ceb1895bf6ef564b5",
"swagger-jsdoc": "^6.2.8",
"terser-webpack-plugin": "^5.3.7",
"url-loader": "^4.1.1",
Expand Down
1 change: 1 addition & 0 deletions alfalfa_web/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AlfalfaAPI {
this.s3 = new S3Client({
credentials,
endpoint: process.env.S3_URL_EXTERNAL || process.env.S3_URL,
forcePathStyle: true,
region
});
}
Expand Down
25 changes: 17 additions & 8 deletions alfalfa_web/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import path from "node:path";
import url from "node:url";
import bodyParser from "body-parser";
import compression from "compression";
import historyApiFallback from "connect-history-api-fallback";
import history from "connect-history-api-fallback";
import express from "express";
import { MongoClient } from "mongodb";
import morgan from "morgan";
import { createClient } from "redis";
import alfalfaServer from "./alfalfa-server";
import apiv2 from "./api-v2";

const isProd = process.env.NODE_ENV === "production";
const redis = createClient({ host: process.env.REDIS_HOST });

MongoClient.connect(process.env.MONGO_URL, { useUnifiedTopology: true })
Expand All @@ -35,13 +36,21 @@ MongoClient.connect(process.env.MONGO_URL, { useUnifiedTopology: true })
});
});

app.get("/redoc", (req, res) => {
const docsPath = path.join(__dirname, "/app/docs.html");
let cachedDocs;
app.get("/redoc", async (req, res) => {
if (isProd && cachedDocs) {
return res.type("html").send(cachedDocs);
}

const docsPath = path.join(__dirname, "app/redoc-static.html");

fsp
.access(docsPath, fsp.constants.F_OK)
.then(() => res.sendFile(docsPath))
.catch(() => res.status(404).type("txt").send("Documentation has not been generated"));
try {
await fsp.access(docsPath, fsp.constants.F_OK);
res.sendFile(docsPath);
if (isProd) cachedDocs = await fsp.readFile(docsPath, "utf-8");
} catch (e) {
res.status(404).type("txt").send("Documentation has not been generated");
}
});

app.use("/api/v2/", apiv2({ api: app.locals.alfalfaServer.api }));
Expand Down Expand Up @@ -82,7 +91,7 @@ MongoClient.connect(process.env.MONGO_URL, { useUnifiedTopology: true })
res.redirect(301, "/docs#tag/Haystack");
});

app.use(historyApiFallback());
app.use(history());
app.use("/", express.static(path.join(__dirname, "app")));

const server = app.listen(80, () => {
Expand Down
15 changes: 4 additions & 11 deletions alfalfa_web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,10 @@ const getSha = () => {
module.exports = {
mode: isProd ? "production" : "development",
devtool: isProd ? false : "source-map",
entry: "./app.js",
entry: "./components/app.js",
cache: {
type: "filesystem"
},
devServer: {
static: {
directory: path.join(__dirname, "public")
},
compress: true,
port: 80
},
watchOptions: {
ignored: ["**/node_modules", "**/scripts", "**/server"]
},
output: {
path: path.resolve(__dirname, "build/app"),
filename: "app.bundle.js"
Expand All @@ -53,6 +43,9 @@ module.exports = {
})
]
},
performance: {
hints: false
},
module: {
rules: [
{
Expand Down

0 comments on commit 26bab6d

Please sign in to comment.