Skip to content

Commit

Permalink
Stop hosting client in fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobfilik committed Jul 10, 2024
1 parent 6b6dbdc commit 1532c90
Show file tree
Hide file tree
Showing 26 changed files with 479 additions and 409 deletions.
50 changes: 0 additions & 50 deletions Dockerfile

This file was deleted.

23 changes: 8 additions & 15 deletions xas-standards-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# This file is for use as a devcontainer and a runtime container
#
# The devcontainer should use the build target and run as root with podman
# or docker with user namespaces.
#
#build api
#copy to runtime
FROM python:3.11 as build

ARG PIP_OPTIONS=.

# Add any system dependencies for the developer/build environment here e.g.
# RUN apt-get update && apt-get upgrade -y && \
# apt-get install -y --no-install-recommends \
# desired-packages \
# && rm -rf /var/lib/apt/lists/*

# set up a virtual environment and put it in PATH
RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH

# Copy any required context for the pip install over
COPY . /context
WORKDIR /context
WORKDIR /api
COPY . .

# install python package into /venv
RUN pip install ${PIP_OPTIONS}
Expand All @@ -32,6 +22,9 @@ FROM python:3.11-slim as runtime
COPY --from=build /venv/ /venv/
ENV PATH=/venv/bin:$PATH

RUN apt-get update && apt-get install libpq5 -y

EXPOSE 5000

# change this entrypoint if it is not the same as the repo
ENTRYPOINT ["xas-standards-api"]
CMD ["--version"]
28 changes: 1 addition & 27 deletions xas-standards-api/src/xas_standards_api/app.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
import os

from fastapi import (
FastAPI,
)
from fastapi.staticfiles import StaticFiles
from fastapi import FastAPI
from fastapi_pagination import add_pagination
from starlette.responses import RedirectResponse

from .routers import admin, open, protected

dev = False

env_value = os.environ.get("FASTAPI_APP_ENV")

if env_value and env_value == "development":
print("RUNNING IN DEV MODE")
dev = True


build_dir = os.environ.get("FRONTEND_BUILD_DIR")

app = FastAPI()

app.include_router(open.router)
app.include_router(protected.router)
app.include_router(admin.router)

add_pagination(app)


@app.get("/login", response_class=RedirectResponse)
async def redirect_home():
# proxy handles log in so if you reach here go home
return "/"


if build_dir:
app.mount("/", StaticFiles(directory="/client/dist", html=True), name="site")
25 changes: 25 additions & 0 deletions xas-standards-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#build client
#build api
#copy to runtime

FROM node:18-bullseye-slim as build-web

WORKDIR /client

RUN yes | npm install -g pnpm

RUN apt update

COPY . .

RUN yes | pnpm install

RUN pnpm vite build

From nginx as host

COPY --from=build-web /client/dist/ /usr/share/nginx/html
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf

# change this entrypoint if it is not the same as the repo
ENTRYPOINT ["nginx","-g", "daemon off;"]
46 changes: 46 additions & 0 deletions xas-standards-client/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
server {
listen 80;
server_name localhost;

#access_log /var/log/nginx/host.access.log main;


location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html =404;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

4 changes: 3 additions & 1 deletion xas-standards-client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { useState, useMemo } from "react";
import { Stack } from "@mui/material";
import { createTheme, ThemeProvider } from "@mui/material/styles";

import ReviewPage from "./components/ReviewPage.tsx";
import ReviewPage from "./components/review/ReviewPage.tsx";
import Terms from "./components/Terms.tsx";

function App() {
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
Expand Down Expand Up @@ -56,6 +57,7 @@ function App() {
<Routes>
<Route path="/" element={<WelcomePage />} />
<Route path="/view" element={<StandardViewerMui />} />
<Route path="/terms" element={<Terms />} />
<Route
path="/submit"
element={
Expand Down
73 changes: 36 additions & 37 deletions xas-standards-client/src/components/DiamondIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
import { SvgIcon } from "@mui/material"
import { SvgIcon } from "@mui/material";

export default function DiamondIcon() {
return (
<SvgIcon fontSize="large" >
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
aria-hidden="true"
role="img"
class="iconify iconify--logos"
width="31.88"
height="32"
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 256 257"
version="1.1"
id="svg3914"
sodipodi:docname="vite.svg"
stroke="currentColor"
fill="currentColor"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)">

<g
transform="matrix(1.0538199,0,0,-1.0538199,0.67781236,254.87384)">
<path d="m 167.021,50.0199 c -6.42,-0.9168 -8.488,-5.9148 -4.598,-11.1019 l 17.776,-23.6981 c 17.752,10.0723 32.708,24.493 43.391,41.843 l -56.569,-7.043" />
<path d="m 74.6574,75.2738 c 6.4203,0.9184 8.4887,5.9121 4.5985,11.0992 l -46.4973,61.999 c -3.8938,5.187 -2.8301,6.248 2.357,2.357 l 61.9891,-46.49 c 5.1873,-3.894 10.1813,-1.823 11.0993,4.595 l 10.959,113.025 c 0.914,6.42 2.417,6.42 3.335,0 l 10.959,-113.042 c 0.918,-6.417 5.912,-8.485 11.099,-4.595 l 62.012,46.507 c 5.188,3.891 6.248,2.83 2.358,-2.357 L 162.425,86.3699 c -3.89,-5.1867 -1.822,-10.182 4.599,-11.0988 l 62.314,-7.7582 c 7.761,15.941 12.12,33.8391 12.12,52.7621 0,66.674 -54.052,120.726 -120.729,120.726 C 54.052,241.001 0,186.949 0,120.275 0,101.342 4.36563,83.434 12.1297,67.4898 l 62.5277,7.784"/>
<path d="m 108.203,16.4551 c -0.918,6.4179 -5.912,8.4859 -11.0995,4.5988 L 78.5465,7.13203 C 88.6414,3.36797 99.3848,0.933984 110.553,0 l -2.35,16.4551"/>
<path d="M 133.457,16.4711 131.106,0.0148438 C 142.258,0.966016 152.978,3.41289 163.06,7.18984 L 144.559,21.0691 c -5.19,3.8899 -10.185,1.8188 -11.102,-4.598"/>
<path d="M 74.6574,50.016 17.8488,57.0879 C 28.5656,39.6781 43.5848,25.2109 61.4137,15.1301 l 17.8422,23.7871 c 3.8902,5.1867 1.8218,10.1808 -4.5985,11.0988"/>
</g>
</svg>
</SvgIcon>
)
}
return (
<SvgIcon fontSize="large">
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
aria-hidden="true"
role="img"
className="iconify iconify--logos"
width="31.88"
height="32"
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 256 257"
version="1.1"
id="svg3914"
sodipodi:docname="vite.svg"
stroke="currentColor"
fill="currentColor"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
>
<g transform="matrix(1.0538199,0,0,-1.0538199,0.67781236,254.87384)">
<path d="m 167.021,50.0199 c -6.42,-0.9168 -8.488,-5.9148 -4.598,-11.1019 l 17.776,-23.6981 c 17.752,10.0723 32.708,24.493 43.391,41.843 l -56.569,-7.043" />
<path d="m 74.6574,75.2738 c 6.4203,0.9184 8.4887,5.9121 4.5985,11.0992 l -46.4973,61.999 c -3.8938,5.187 -2.8301,6.248 2.357,2.357 l 61.9891,-46.49 c 5.1873,-3.894 10.1813,-1.823 11.0993,4.595 l 10.959,113.025 c 0.914,6.42 2.417,6.42 3.335,0 l 10.959,-113.042 c 0.918,-6.417 5.912,-8.485 11.099,-4.595 l 62.012,46.507 c 5.188,3.891 6.248,2.83 2.358,-2.357 L 162.425,86.3699 c -3.89,-5.1867 -1.822,-10.182 4.599,-11.0988 l 62.314,-7.7582 c 7.761,15.941 12.12,33.8391 12.12,52.7621 0,66.674 -54.052,120.726 -120.729,120.726 C 54.052,241.001 0,186.949 0,120.275 0,101.342 4.36563,83.434 12.1297,67.4898 l 62.5277,7.784" />
<path d="m 108.203,16.4551 c -0.918,6.4179 -5.912,8.4859 -11.0995,4.5988 L 78.5465,7.13203 C 88.6414,3.36797 99.3848,0.933984 110.553,0 l -2.35,16.4551" />
<path d="M 133.457,16.4711 131.106,0.0148438 C 142.258,0.966016 152.978,3.41289 163.06,7.18984 L 144.559,21.0691 c -5.19,3.8899 -10.185,1.8188 -11.102,-4.598" />
<path d="M 74.6574,50.016 17.8488,57.0879 C 28.5656,39.6781 43.5848,25.2109 61.4137,15.1301 l 17.8422,23.7871 c 3.8902,5.1867 1.8218,10.1808 -4.5985,11.0988" />
</g>
</svg>
</SvgIcon>
);
}
4 changes: 4 additions & 0 deletions xas-standards-client/src/components/ElementSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ function ElementSelector(props: {
>
<SimplePeriodicTable
onClickElement={(el) => {
if (el >= elements.length) {
el = 0;
}

props.setSelectedElement(el);
setAnchorEl(null);
}}
Expand Down
Loading

0 comments on commit 1532c90

Please sign in to comment.