From eabadf09d29a82d21d3169a83b6244c7e1bacca7 Mon Sep 17 00:00:00 2001 From: Jonas Braathen <jonas.braathen@usit.uio.no> Date: Tue, 5 Oct 2021 22:10:50 +0200 Subject: [PATCH] Make all URLs relative. Move /oidc and /admin endpoints up from /api and proxy them during development. --- frontend/src/components/debug/index.tsx | 2 +- frontend/src/hooks/useOus/index.tsx | 4 +--- frontend/src/routes/frontpage/components/loginpage.tsx | 2 +- frontend/src/routes/index.tsx | 2 +- frontend/src/routes/register/stepSummary.tsx | 2 +- frontend/src/routes/sponsor/frontpage/index.tsx | 4 +--- frontend/src/setupProxy.js | 8 +++++++- gregsite/urls.py | 4 ++-- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/debug/index.tsx b/frontend/src/components/debug/index.tsx index f38c93bd..1097897f 100644 --- a/frontend/src/components/debug/index.tsx +++ b/frontend/src/components/debug/index.tsx @@ -30,7 +30,7 @@ export const Debug = () => { if (!didContactApi) { setDidContactApi(true) - fetch('http://localhost:3000/api/health/') + fetch('/api/health/') .then((res) => res.text()) .then((result) => { if (result === 'OK') { diff --git a/frontend/src/hooks/useOus/index.tsx b/frontend/src/hooks/useOus/index.tsx index 99188e76..64c12dba 100644 --- a/frontend/src/hooks/useOus/index.tsx +++ b/frontend/src/hooks/useOus/index.tsx @@ -9,9 +9,7 @@ type OuData = { function useOus(): OuData[] { const [ous, setOus] = useState<OuData[]>([]) const getOptions = async () => { - const response = await fetch( - 'http://localhost:3000/api/ui/v1/ous/?format=json' - ) + const response = await fetch('/api/ui/v1/ous/?format=json') if (response.ok) { const ousJson = await response.json() setOus(ousJson.ous) diff --git a/frontend/src/routes/frontpage/components/loginpage.tsx b/frontend/src/routes/frontpage/components/loginpage.tsx index b94015ae..711648f8 100644 --- a/frontend/src/routes/frontpage/components/loginpage.tsx +++ b/frontend/src/routes/frontpage/components/loginpage.tsx @@ -20,7 +20,7 @@ export default function LoginPage() { <Container maxWidth="sm"> <h2>{t('header')}</h2> <StyledParagraph>{t('description')}</StyledParagraph> - <HrefButton to="/api/oidc/authenticate">{t('login')}</HrefButton> + <HrefButton to="/oidc/authenticate/">{t('login')}</HrefButton> </Container> </StyledWrapper> ) diff --git a/frontend/src/routes/index.tsx b/frontend/src/routes/index.tsx index b0796e24..4504a47c 100644 --- a/frontend/src/routes/index.tsx +++ b/frontend/src/routes/index.tsx @@ -50,7 +50,7 @@ export default function App() { <ProtectedRoute path='/sponsor'> <Sponsor /> </ProtectedRoute> - <Route path='register'> + <Route path='/register'> <Register /> </Route> <Route> diff --git a/frontend/src/routes/register/stepSummary.tsx b/frontend/src/routes/register/stepSummary.tsx index 2d24c768..b855da28 100644 --- a/frontend/src/routes/register/stepSummary.tsx +++ b/frontend/src/routes/register/stepSummary.tsx @@ -35,7 +35,7 @@ const StepSummary = forwardRef((props: StepSummaryProperties, ref: Ref<PersonFor email: data.email, } console.log('submitting', JSON.stringify(payload)) - fetch('http://localhost:3000/api/ui/v1/register/', postJsonOpts(payload)) + fetch('/api/ui/v1/register/', postJsonOpts(payload)) .then((res) => res.text()) .then((result) => { console.log('result', result) diff --git a/frontend/src/routes/sponsor/frontpage/index.tsx b/frontend/src/routes/sponsor/frontpage/index.tsx index e1fa859e..bb48c687 100644 --- a/frontend/src/routes/sponsor/frontpage/index.tsx +++ b/frontend/src/routes/sponsor/frontpage/index.tsx @@ -151,9 +151,7 @@ function FrontPage() { const [t] = useTranslation(['common']) const fetchGuestsInfo = async () => { - const response = await fetch( - 'http://localhost:3000/api/ui/v1/persons/?format=json' - ) + const response = await fetch('/api/ui/v1/persons/?format=json') const jsonResponse = await response.json() if (response.ok) { const roles = await jsonResponse.roles diff --git a/frontend/src/setupProxy.js b/frontend/src/setupProxy.js index a7d60f51..1edb7f68 100644 --- a/frontend/src/setupProxy.js +++ b/frontend/src/setupProxy.js @@ -2,7 +2,13 @@ const { createProxyMiddleware } = require('http-proxy-middleware') module.exports = (app) => { app.use( - '/api', + [ + '/admin*', // Django admin + '/staticfiles*', // Django static files + '/api*', // API + '/schema*', // API schema + '/oidc*', // OpenID connect login endpoint + ], createProxyMiddleware({ target: 'http://localhost:8000', changeOrigin: true, diff --git a/gregsite/urls.py b/gregsite/urls.py index be0f570b..07e64cd7 100644 --- a/gregsite/urls.py +++ b/gregsite/urls.py @@ -22,8 +22,8 @@ from gregui import urls as ui_urls admin.autodiscover() urlpatterns = [ - path("api/admin/", admin.site.urls), + path("admin/", admin.site.urls), path("", include(greg_urls.urlpatterns)), path("", include(ui_urls.urlpatterns)), - path("api/oidc/", include("mozilla_django_oidc.urls")), + path("oidc/", include("mozilla_django_oidc.urls")), ] -- GitLab