Skip to content
Snippets Groups Projects
Commit eabadf09 authored by Jonas Braathen's avatar Jonas Braathen
Browse files

Make all URLs relative. Move /oidc and /admin endpoints up from /api and proxy...

Make all URLs relative. Move /oidc and /admin endpoints up from /api and proxy them during development.
parent dd0cb18d
No related branches found
No related tags found
1 merge request!84Greg 51 deploy frontend
Pipeline #95810 passed
...@@ -30,7 +30,7 @@ export const Debug = () => { ...@@ -30,7 +30,7 @@ export const Debug = () => {
if (!didContactApi) { if (!didContactApi) {
setDidContactApi(true) setDidContactApi(true)
fetch('http://localhost:3000/api/health/') fetch('/api/health/')
.then((res) => res.text()) .then((res) => res.text())
.then((result) => { .then((result) => {
if (result === 'OK') { if (result === 'OK') {
......
...@@ -9,9 +9,7 @@ type OuData = { ...@@ -9,9 +9,7 @@ type OuData = {
function useOus(): OuData[] { function useOus(): OuData[] {
const [ous, setOus] = useState<OuData[]>([]) const [ous, setOus] = useState<OuData[]>([])
const getOptions = async () => { const getOptions = async () => {
const response = await fetch( const response = await fetch('/api/ui/v1/ous/?format=json')
'http://localhost:3000/api/ui/v1/ous/?format=json'
)
if (response.ok) { if (response.ok) {
const ousJson = await response.json() const ousJson = await response.json()
setOus(ousJson.ous) setOus(ousJson.ous)
......
...@@ -20,7 +20,7 @@ export default function LoginPage() { ...@@ -20,7 +20,7 @@ export default function LoginPage() {
<Container maxWidth="sm"> <Container maxWidth="sm">
<h2>{t('header')}</h2> <h2>{t('header')}</h2>
<StyledParagraph>{t('description')}</StyledParagraph> <StyledParagraph>{t('description')}</StyledParagraph>
<HrefButton to="/api/oidc/authenticate">{t('login')}</HrefButton> <HrefButton to="/oidc/authenticate/">{t('login')}</HrefButton>
</Container> </Container>
</StyledWrapper> </StyledWrapper>
) )
......
...@@ -50,7 +50,7 @@ export default function App() { ...@@ -50,7 +50,7 @@ export default function App() {
<ProtectedRoute path='/sponsor'> <ProtectedRoute path='/sponsor'>
<Sponsor /> <Sponsor />
</ProtectedRoute> </ProtectedRoute>
<Route path='register'> <Route path='/register'>
<Register /> <Register />
</Route> </Route>
<Route> <Route>
......
...@@ -35,7 +35,7 @@ const StepSummary = forwardRef((props: StepSummaryProperties, ref: Ref<PersonFor ...@@ -35,7 +35,7 @@ const StepSummary = forwardRef((props: StepSummaryProperties, ref: Ref<PersonFor
email: data.email, email: data.email,
} }
console.log('submitting', JSON.stringify(payload)) 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((res) => res.text())
.then((result) => { .then((result) => {
console.log('result', result) console.log('result', result)
......
...@@ -151,9 +151,7 @@ function FrontPage() { ...@@ -151,9 +151,7 @@ function FrontPage() {
const [t] = useTranslation(['common']) const [t] = useTranslation(['common'])
const fetchGuestsInfo = async () => { const fetchGuestsInfo = async () => {
const response = await fetch( const response = await fetch('/api/ui/v1/persons/?format=json')
'http://localhost:3000/api/ui/v1/persons/?format=json'
)
const jsonResponse = await response.json() const jsonResponse = await response.json()
if (response.ok) { if (response.ok) {
const roles = await jsonResponse.roles const roles = await jsonResponse.roles
......
...@@ -2,7 +2,13 @@ const { createProxyMiddleware } = require('http-proxy-middleware') ...@@ -2,7 +2,13 @@ const { createProxyMiddleware } = require('http-proxy-middleware')
module.exports = (app) => { module.exports = (app) => {
app.use( app.use(
'/api', [
'/admin*', // Django admin
'/staticfiles*', // Django static files
'/api*', // API
'/schema*', // API schema
'/oidc*', // OpenID connect login endpoint
],
createProxyMiddleware({ createProxyMiddleware({
target: 'http://localhost:8000', target: 'http://localhost:8000',
changeOrigin: true, changeOrigin: true,
......
...@@ -22,8 +22,8 @@ from gregui import urls as ui_urls ...@@ -22,8 +22,8 @@ from gregui import urls as ui_urls
admin.autodiscover() admin.autodiscover()
urlpatterns = [ urlpatterns = [
path("api/admin/", admin.site.urls), path("admin/", admin.site.urls),
path("", include(greg_urls.urlpatterns)), path("", include(greg_urls.urlpatterns)),
path("", include(ui_urls.urlpatterns)), path("", include(ui_urls.urlpatterns)),
path("api/oidc/", include("mozilla_django_oidc.urls")), path("oidc/", include("mozilla_django_oidc.urls")),
] ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment