Skip to content

refactor(React template): Add easier setup using HashRoute #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions templates/react/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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("/<path:path>")
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")
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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(
<LocalStackThemeProvider useExtensionLayout>
<BrowserRouter basename={getBaseName()}>
<HashRouter>
<CustomRoutes />
</BrowserRouter >
</HashRouter>
</LocalStackThemeProvider>,
document.getElementById('root'),
document.getElementById("root")
);