From 011d9512137277b6121318353d86e8adfc2c25f4 Mon Sep 17 00:00:00 2001 From: Pive01 Date: Fri, 30 May 2025 15:39:00 +0200 Subject: [PATCH 1/2] Add easier setup using hashroute --- .../{{cookiecutter.module_name}}/api/web.py | 15 ++++++++--- .../frontend/package.json | 7 ++--- .../frontend/src/index.tsx | 27 ++++++------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/templates/react/{{cookiecutter.project_slug}}/backend/{{cookiecutter.module_name}}/api/web.py b/templates/react/{{cookiecutter.project_slug}}/backend/{{cookiecutter.module_name}}/api/web.py index 78faf4d..8a65981 100644 --- a/templates/react/{{cookiecutter.project_slug}}/backend/{{cookiecutter.module_name}}/api/web.py +++ b/templates/react/{{cookiecutter.project_slug}}/backend/{{cookiecutter.module_name}}/api/web.py @@ -1,12 +1,21 @@ -from localstack.http import route, Request, Response +import logging + +from localstack.http import Request, Response, route from .. import static +LOG = logging.getLogger(__name__) + + class WebApp: @route("/") def index(self, request: Request, *args, **kwargs): return Response.for_resource(static, "index.html") - + @route("/") def index2(self, request: Request, path: str, **kwargs): - return Response.for_resource(static, path) + try: + return Response.for_resource(static, path) + except Exception: + LOG.debug(f"File {path} not found, serving index.html") + return Response.for_resource(static, "index.html") diff --git a/templates/react/{{cookiecutter.project_slug}}/frontend/package.json b/templates/react/{{cookiecutter.project_slug}}/frontend/package.json index 53661c8..847c8ac 100644 --- a/templates/react/{{cookiecutter.project_slug}}/frontend/package.json +++ b/templates/react/{{cookiecutter.project_slug}}/frontend/package.json @@ -8,9 +8,6 @@ "@emotion/styled": "^11.11.5", "@localstack/integrations": "^1.0.0", "@mui/material": "^5.15.20", - "@testing-library/react": "^13.4.0", - "@types/node": "^16.18.99", - "@types/react-dom": "^17.0.11", "react": "^17.0.2", "react-dom": "^17.0.2", "react-router-dom": "^6.24.0", @@ -19,6 +16,10 @@ }, "devDependencies": { "@esbuild-plugins/node-modules-polyfill": "^0.1.4", + "@testing-library/react": "^13.4.0", + "@types/node": "^16.18.99", + "@types/react": "^19.1.6", + "@types/react-dom": "^17.0.11", "concurrently": "^8.2.2", "esbuild": "^0.16.6", "esbuild-envfile-plugin": "^1.0.2", diff --git a/templates/react/{{cookiecutter.project_slug}}/frontend/src/index.tsx b/templates/react/{{cookiecutter.project_slug}}/frontend/src/index.tsx index cddd6a1..0633444 100644 --- a/templates/react/{{cookiecutter.project_slug}}/frontend/src/index.tsx +++ b/templates/react/{{cookiecutter.project_slug}}/frontend/src/index.tsx @@ -1,25 +1,14 @@ -import ReactDOM from 'react-dom'; -import './index.css'; -import { CustomRoutes } from './CustomRoutes'; -import { BrowserRouter } from 'react-router-dom'; -import { LocalStackThemeProvider } from '@localstack/integrations' -import { DEVELOPMENT_ENVIRONMENT } from './constants'; - -const EXTENSION_NAME = '{{cookiecutter.project_slug}}' - -const getBaseName = () => { - if (window.location.origin.includes(EXTENSION_NAME) || DEVELOPMENT_ENVIRONMENT) { - return ''; - } - - return `/_extension/${EXTENSION_NAME}`; -}; +import ReactDOM from "react-dom"; +import "./index.css"; +import { CustomRoutes } from "./CustomRoutes"; +import { HashRouter } from "react-router-dom"; +import { LocalStackThemeProvider } from "@localstack/integrations"; ReactDOM.render( - + - + , - document.getElementById('root'), + document.getElementById("root") ); From 79a6f68d6270210fcee38a932078c097f25a6101 Mon Sep 17 00:00:00 2001 From: Pive01 Date: Fri, 30 May 2025 15:43:51 +0200 Subject: [PATCH 2/2] Remove unused constant --- templates/react/{{cookiecutter.project_slug}}/Makefile | 4 ++-- .../{{cookiecutter.project_slug}}/frontend/src/constants.ts | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 templates/react/{{cookiecutter.project_slug}}/frontend/src/constants.ts diff --git a/templates/react/{{cookiecutter.project_slug}}/Makefile b/templates/react/{{cookiecutter.project_slug}}/Makefile index d683965..e0e9417 100644 --- a/templates/react/{{cookiecutter.project_slug}}/Makefile +++ b/templates/react/{{cookiecutter.project_slug}}/Makefile @@ -43,10 +43,10 @@ build-frontend: # Build the React app @if [ ! -d "$(FRONTEND_FOLDER)/node_modules" ]; then \ $(MAKE) install-frontend; \ fi - cd $(FRONTEND_FOLDER); rm -rf build && REACT_APP_DEVELOPMENT_ENVIRONMENT=false NODE_ENV=prod npm run build + cd $(FRONTEND_FOLDER); rm -rf build && NODE_ENV=prod npm run build start-frontend: ## Start the frontend in dev mode (hot reload) - cd $(FRONTEND_FOLDER); REACT_APP_DEVELOPMENT_ENVIRONMENT=true yarn start + cd $(FRONTEND_FOLDER); yarn start install: venv install-backend install-frontend ## Install dependencies diff --git a/templates/react/{{cookiecutter.project_slug}}/frontend/src/constants.ts b/templates/react/{{cookiecutter.project_slug}}/frontend/src/constants.ts deleted file mode 100644 index 2a85b5c..0000000 --- a/templates/react/{{cookiecutter.project_slug}}/frontend/src/constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const DEVELOPMENT_ENVIRONMENT = process.env.REACT_APP_DEVELOPMENT_ENVIRONMENT === "true";