Skip to content

Commit

Permalink
Add support for custom base path and add health check
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgxvii committed Oct 2, 2024
1 parent f0a1423 commit 20e62f6
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ORY_SDK_URL=http://localhost:4433
HYDRA_ADMIN_URL=http://localhost:4445
HYDRA_PUBLIC_URL=http://localhost:4444
BASE_PATH=/kratos-ui
NEXT_PUBLIC_KRATOS_PUBLIC_URL=http://localhost:3000/kratos-ui
2 changes: 2 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
basePath: process.env.BASE_PATH || "",
assetPrefix: process.env.BASE_PATH ?? "" + "/",
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@types/react": "~17.0.19",
"@types/request": "^2.48.7",
"@types/styled-components": "^5.1.13",
"@types/uuid": "^10.0.0",
"cypress": "^8.7.0",
"eslint": "7.32.0",
"eslint-config-next": "12.0.3",
Expand Down
4 changes: 4 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "../styles/globals.css"
import { theme, globalStyles, ThemeProps } from "@ory/themes"
import type { AppProps } from "next/app"
import Head from "next/head"
import { ToastContainer } from "react-toastify"
import "react-toastify/dist/ReactToastify.css"
import { ThemeProvider } from "styled-components"
Expand All @@ -13,6 +14,9 @@ const GlobalStyle = createGlobalStyle((props: ThemeProps) =>
function MyApp({ Component, pageProps }: AppProps) {
return (
<div data-testid="app-react">
<Head>
<base href="/kratos-ui/" />
</Head>
<ThemeProvider theme={theme}>
<GlobalStyle />
<Component {...pageProps} />
Expand Down
5 changes: 0 additions & 5 deletions pages/health/alive.ts

This file was deleted.

23 changes: 23 additions & 0 deletions pages/health/alive.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ServerResponse } from "http"
import { GetServerSideProps } from "next"
import React from "react"

// Use Node.js's ServerResponse

const Alive = () => {
return <div>Healthy!</div>
}

export const getServerSideProps: GetServerSideProps = async ({
res,
}: {
res: ServerResponse
}) => {
res.statusCode = 200

return {
props: {},
}
}

export default Alive
5 changes: 0 additions & 5 deletions pages/health/ready.ts

This file was deleted.

21 changes: 21 additions & 0 deletions pages/health/ready.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ServerResponse } from "http"
import { GetServerSideProps } from "next"
import React from "react"

const Ready = () => {
return <div>Ready!</div>
}

export const getServerSideProps: GetServerSideProps = async ({
res,
}: {
res: ServerResponse
}) => {
res.statusCode = 200

return {
props: {},
}
}

export default Ready
2 changes: 1 addition & 1 deletion pkg/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Configuration, FrontendApi } from "@ory/client"
import { edgeConfig } from "@ory/integrations/next"

const localConfig = {
basePath: process.env.NEXT_PUBLIC_KRATOS_PUBLIC_URL,
basePath: process.env.NEXT_PUBLIC_KRATOS_PUBLIC_URL ?? "" + "/api/.ory",
baseOptions: {
withCredentials: true,
},
Expand Down
31 changes: 18 additions & 13 deletions pkg/styled/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import cn from "classnames"
import styled from "styled-components"

const BASE_URL = process.env.BASE_PATH || ""

export const MarginCard = styled(Card)`
margin-top: 70px;
margin-bottom: 18px;
Expand Down Expand Up @@ -106,17 +108,20 @@ export const DocsButton = ({
testid,
disabled,
unresponsive,
}: DocsButtonProps) => (
<div className={cn("col-xs-4", { "col-md-12": !unresponsive })}>
<div className="box">
<TextLeftButton
onClick={onClick}
disabled={disabled}
data-testid={testid}
href={href}
>
{title}
</TextLeftButton>
}: DocsButtonProps) => {
const url = BASE_URL + href
return (
<div className={cn("col-xs-4", { "col-md-12": !unresponsive })}>
<div className="box">
<TextLeftButton
onClick={onClick}
disabled={disabled}
data-testid={testid}
href={url}
>
{title}
</TextLeftButton>
</div>
</div>
</div>
)
)
}

0 comments on commit 20e62f6

Please sign in to comment.