Skip to content

Commit 42884fe

Browse files
authored
ci(build): switch from getServerSideProps to getInitialProps (#56)
2 parents 4d568d7 + cf3eff3 commit 42884fe

File tree

7 files changed

+45
-23
lines changed

7 files changed

+45
-23
lines changed

.github/workflows/nextjs.yml

+16-10
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
build:
3030
runs-on: ubuntu-latest
3131
steps:
32-
- name: Checkout
33-
uses: actions/checkout@v3
32+
- name: Checkout 🛎️
33+
uses: actions/checkout@v4.1.3
3434
- name: Detect package manager
3535
id: detect-package-manager
3636
run: |
@@ -74,15 +74,15 @@ jobs:
7474
- name: Install dependencies
7575
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
7676
- name: Build with Next.js
77-
run: ${{ steps.detect-package-manager.outputs.runner }} next build
77+
run: ${{ steps.detect-package-manager.outputs.runner }} build && touch ./out/.nojekyll
7878
env:
7979
NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN: ${{ secrets.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN }}
8080
# - name: Static HTML export with Next.js
8181
# run: ${{ steps.detect-package-manager.outputs.runner }} next export
82-
- name: Upload artifact
83-
uses: actions/upload-pages-artifact@v1
84-
with:
85-
path: ./out
82+
# - name: Upload artifact
83+
# uses: actions/upload-pages-artifact@v4
84+
# with:
85+
# path: ./out
8686

8787
# Deployment job
8888
deploy:
@@ -92,6 +92,12 @@ jobs:
9292
runs-on: ubuntu-latest
9393
needs: build
9494
steps:
95-
- name: Deploy to GitHub Pages
96-
id: deployment
97-
uses: actions/deploy-pages@v1
95+
# - name: Deploy to GitHub Pages
96+
# id: deployment
97+
# uses: actions/deploy-pages@v4
98+
- name: Deploy 🚀
99+
uses: JamesIves/github-pages-deploy-action@v4.6.0
100+
with:
101+
token: ${{ secrets.GITHUB_TOKEN }}
102+
branch: main
103+
folder: out

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# production
1212
/build
1313
/.next
14+
out
1415

1516
# misc
1617
.DS_Store

jest.setup.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
import "@testing-library/jest-dom";
33
import { TextEncoder, TextDecoder } from "util";
44

5+
jest.mock("next/config", () => () => ({
6+
publicRuntimeConfig: {
7+
NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN: "https://rekor.sigstore.dev",
8+
},
9+
}));
10+
511
Object.assign(global, { TextDecoder, TextEncoder });

next.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ const nextConfig = {
77
process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN,
88
},
99
reactStrictMode: true,
10+
assetPrefix: "./",
11+
images: {
12+
loader: "akamai",
13+
path: "",
14+
},
15+
output: "export",
1016
publicRuntimeConfig: {
1117
// remove private env variables
1218
processEnv: Object.fromEntries(

src/modules/api/context.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
useState,
88
} from "react";
99
import { RekorClient } from "rekor";
10+
import getConfig from "next/config";
1011

1112
export interface RekorClientContext {
1213
client: RekorClient;
@@ -22,6 +23,7 @@ export const RekorClientProvider: FunctionComponent<PropsWithChildren<{}>> = ({
2223
children,
2324
}) => {
2425
const [baseUrl, setBaseUrl] = useState<string>();
26+
const { publicRuntimeConfig } = getConfig();
2527

2628
const context: RekorClientContext = useMemo(() => {
2729
/*
@@ -31,8 +33,8 @@ export const RekorClientProvider: FunctionComponent<PropsWithChildren<{}>> = ({
3133
https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
3234
*/
3335
if (baseUrl === undefined) {
34-
if (process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN) {
35-
setBaseUrl(process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN);
36+
if (publicRuntimeConfig.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN) {
37+
setBaseUrl(publicRuntimeConfig.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN);
3638
} else {
3739
setBaseUrl("https://rekor.sigstore.dev");
3840
}

src/pages/_app.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import type { AppProps } from "next/app";
22
import "@patternfly/react-core/dist/styles/base.css";
3+
import { NextPageContext } from "next";
34

45
function App({ Component, pageProps }: AppProps) {
56
return <Component {...pageProps} />;
67
}
78

9+
App.getInitialProps = async (_ctx: NextPageContext) => {
10+
return {
11+
props: {
12+
NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN: process.env
13+
.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN
14+
? process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN
15+
: null,
16+
}, // gets passed to the page component as props
17+
};
18+
};
19+
820
export default App;

src/pages/index.tsx

-11
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,3 @@ const PageComponent: NextPage = () => (
112112
</RekorClientProvider>
113113
);
114114
export default PageComponent;
115-
116-
export async function getServerSideProps() {
117-
return {
118-
props: {
119-
NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN: process.env
120-
.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN
121-
? process.env.NEXT_PUBLIC_REKOR_DEFAULT_DOMAIN
122-
: null,
123-
}, // gets passed to the page component as props
124-
};
125-
}

0 commit comments

Comments
 (0)