Skip to content

Commit 69965ec

Browse files
authored
Fix netlify deployment (DeFiCh#747)
1 parent 9c34976 commit 69965ec

7 files changed

Lines changed: 1625 additions & 333 deletions

File tree

.github/workflows/deploy-gh-pages.yml

Lines changed: 0 additions & 77 deletions
This file was deleted.

.github/workflows/nextjs.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Deploy Next.js site to Pages
2+
3+
on:
4+
# Runs on pushes targeting the default branch
5+
push:
6+
branches: ["main"]
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
18+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: false
22+
23+
jobs:
24+
# Build job
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: Detect package manager
31+
id: detect-package-manager
32+
run: |
33+
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
34+
echo "manager=yarn" >> $GITHUB_OUTPUT
35+
echo "command=install" >> $GITHUB_OUTPUT
36+
echo "runner=yarn" >> $GITHUB_OUTPUT
37+
exit 0
38+
elif [ -f "${{ github.workspace }}/package.json" ]; then
39+
echo "manager=pnpm" >> $GITHUB_OUTPUT
40+
echo "command=ci" >> $GITHUB_OUTPUT
41+
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
42+
exit 0
43+
else
44+
echo "Unable to determine package manager"
45+
exit 1
46+
fi
47+
- name: Setup Node
48+
uses: actions/setup-node@v4
49+
with:
50+
node-version: "20"
51+
cache: ${{ steps.detect-package-manager.outputs.manager }}
52+
- name: Setup Pages
53+
uses: actions/configure-pages@v5
54+
with:
55+
# Automatically inject basePath in your Next.js configuration file and disable
56+
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
57+
#
58+
# You may remove this line if you want to manage the configuration yourself.
59+
static_site_generator: next
60+
- name: Restore cache
61+
uses: actions/cache@v4
62+
with:
63+
path: |
64+
.next/cache
65+
# Generate a new cache whenever packages or source files change.
66+
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
67+
# If source files changed but packages didn't, rebuild from a prior cache.
68+
restore-keys: |
69+
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
70+
- name: Install dependencies
71+
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
72+
- name: Build with Next.js
73+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
74+
- name: Upload artifact
75+
uses: actions/upload-pages-artifact@v3
76+
with:
77+
path: ./out
78+
79+
# Deployment job
80+
deploy:
81+
environment:
82+
name: github-pages
83+
url: ${{ steps.deployment.outputs.page_url }}
84+
runs-on: ubuntu-latest
85+
needs: build
86+
steps:
87+
- name: Deploy to GitHub Pages
88+
id: deployment
89+
uses: actions/deploy-pages@v4

netlify.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,49 @@
22
command = "pnpm run build"
33
publish = ".next"
44

5+
[[plugins]]
6+
package = "@netlify/plugin-lighthouse"
7+
58
[[plugins]]
69
package = "@netlify/plugin-nextjs"
710

811
[[headers]]
912
for = "/keys/security@defichain.com.public.key"
1013
[headers.values]
1114
Content-Type = "text/plain"
15+
16+
[[redirects]]
17+
from = "http://defichain.com/*"
18+
to = "https://defichain.com/:splat"
19+
status = 301
20+
force = true
21+
22+
[[redirects]]
23+
from = "http://zhs.defichain.com/*"
24+
to = "https://defichain.com/zh-Hans/:splat"
25+
status = 301
26+
force = true
27+
28+
[[redirects]]
29+
from = "https://zhs.defichain.com/*"
30+
to = "https://defichain.com/zh-Hans/:splat"
31+
status = 301
32+
force = true
33+
34+
[[redirects]]
35+
from = "http://zht.defichain.com/*"
36+
to = "https://defichain.com/zh-Hant/:splat"
37+
status = 301
38+
force = true
39+
40+
[[redirects]]
41+
from = "https://zht.defichain.com/*"
42+
to = "https://defichain.com/zh-Hant/:splat"
43+
status = 301
44+
force = true
45+
46+
[[redirects]]
47+
from = "https://defichain.com/dfi-token"
48+
to = "https://defichain.com/dfi"
49+
status = 301
50+
force = true

next.config.js

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,86 @@
1+
const securityHeaders = [
2+
{
3+
key: "Content-Security-Policy",
4+
value:
5+
`default-src 'none';` +
6+
`base-uri 'none';` +
7+
`child-src 'self' app.netlify.com;` +
8+
`form-action 'none';` +
9+
`frame-ancestors 'none';` +
10+
`img-src 'self' images.prismic.io assets.coingecko.com s2.coinmarketcap.com *.cloudfront.net data:;` +
11+
`media-src 'self';` +
12+
`object-src 'none';` +
13+
`script-src 'self' ajax.googleapis.com widgets.coingecko.com files.coinmarketcap.com 3rdparty-apis.coinmarketcap.com app.netlify.com netlify-cdp-loader.netlify.app *.googletagmanager.com ${
14+
process.env.NODE_ENV === "development" ? `'unsafe-eval'` : ""
15+
} https://connect.facebook.net;` +
16+
`script-src-elem 'self' ajax.googleapis.com widgets.coingecko.com files.coinmarketcap.com 3rdparty-apis.coinmarketcap.com *.googletagmanager.com;` +
17+
`style-src 'self' fonts.googleapis.com 'unsafe-inline' files.coinmarketcap.com 'unsafe-inline';` +
18+
`font-src 'self' fonts.gstatic.com;` +
19+
`connect-src 'self' api.coingecko.com 3rdparty-apis.coinmarketcap.com wss://cable.coingecko.com ocean.defichain.com api.github.com *.google-analytics.com;`,
20+
},
21+
{
22+
key: "Referrer-Policy",
23+
value: "same-origin",
24+
},
25+
{
26+
key: "X-Content-Type-Options",
27+
value: "nosniff",
28+
},
29+
{
30+
key: "X-Frame-Options",
31+
value: "DENY",
32+
},
33+
{
34+
key: "X-XSS-Protection",
35+
value: "1; mode=block",
36+
},
37+
{
38+
key: "Strict-Transport-Security",
39+
value: "max-age=63072000; includeSubDomains; preload",
40+
},
41+
];
42+
143
module.exports = {
2-
output: "export",
344
experimental: {
445
forceSwcTransforms: true,
546
},
647
reactStrictMode: true,
748
swcMinify: true,
849
pageExtensions: ["page.tsx", "page.ts"],
50+
async headers() {
51+
return [
52+
{
53+
source: "/(.*)",
54+
headers: securityHeaders,
55+
},
56+
];
57+
},
958
images: {
1059
domains: ["images.prismic.io"],
1160
unoptimized: true,
1261
},
62+
async redirects() {
63+
return [
64+
{
65+
source: "/learn/:path*",
66+
destination: "/404",
67+
permanent: false,
68+
},
69+
{
70+
source: "/media",
71+
destination: "/404",
72+
permanent: false,
73+
},
74+
{
75+
source: "/bug-bounty",
76+
destination: "/404",
77+
permanent: false,
78+
},
79+
{
80+
source: "/security",
81+
destination: "/404",
82+
permanent: false,
83+
},
84+
];
85+
},
1386
};

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
"@prismicio/react": "^2.7.3",
2121
"@waveshq/standard-defichain-jellyfishsdk": "^3.0.1",
2222
"@waveshq/standard-web": "^3.0.1",
23-
"next": "13.5.8",
24-
"react": "18.2.0",
25-
"react-dom": "18.2.0",
2623
"bignumber.js": "^9.1.2",
2724
"classnames": "^2.3.2",
2825
"gray-matter": "^4.0.3",
@@ -41,6 +38,8 @@
4138
},
4239
"devDependencies": {
4340
"@cypress/code-coverage": "^3.12.9",
41+
"@netlify/plugin-lighthouse": "^5.0.0",
42+
"@netlify/plugin-nextjs": "^4.41.1",
4443
"@tailwindcss/typography": "^0.5.10",
4544
"@testing-library/cypress": "^9.0.0",
4645
"@types/lodash": "^4.14.201",

0 commit comments

Comments
 (0)