Skip to content

Commit d65fa77

Browse files
committed
[add] 404 NGO page
[optimize] update Next.js configuration, Docker file & GitHub actions [optimize] upgrade to Node.js 20, KoAJAX 3, MobX RESTful 1 & other latest Upstream packages
1 parent eec8b88 commit d65fa77

15 files changed

+2362
-2261
lines changed

.github/workflows/deploy-production.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ jobs:
2424

2525
- name: Inject Environment variables
2626
run: |
27+
echo "BOX_NAME=${BOX_NAME@L}" >> "${GITHUB_ENV}"
28+
echo "BOX_URL=${BOX_URL@L}" >> "${GITHUB_ENV}"
2729
cat > .env.local <<EOF
2830
${{ secrets.ENV_FILE }}
2931
EOF
30-
- uses: docker/setup-qemu-action@v2
31-
- uses: docker/setup-buildx-action@v2
32+
- uses: docker/setup-qemu-action@v3
33+
- uses: docker/setup-buildx-action@v3
3234

3335
- name: Build Image
34-
uses: docker/build-push-action@v3
36+
uses: docker/build-push-action@v6
3537
with:
3638
context: .
3739
platforms: linux/amd64
@@ -44,13 +46,14 @@ jobs:
4446
mv ${{ env.ARTIFACT_PATH }} ./docker-compose.yml ./start.sh ./build
4547
4648
- name: Transport Image
47-
uses: garygrossgarten/github-action-scp@release
49+
uses: appleboy/scp-action@v0.1.7
4850
with:
49-
local: ./build
50-
remote: /tmp
51+
source: ./build/*.*
52+
target: /tmp
5153
host: ${{ secrets.HOST }}
5254
username: ${{ secrets.USER }}
5355
password: ${{ secrets.SSH_KEY }}
56+
strip_components: 1
5457

5558
- name: Run Image
5659
uses: garygrossgarten/github-action-ssh@release

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ jobs:
5050
- tag: a
5151
text: ${{ github.ref }}
5252
href: ${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref_name }}
53+
- - tag: text
54+
text: 提交作者:
55+
- tag: a
56+
text: ${{ github.actor }}
57+
href: ${{ github.server_url }}/${{ github.actor }}
5358
- - tag: text
5459
text: 预览链接:
5560
- tag: a

.github/workflows/pull-request.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }}
16+
with:
17+
submodules: recursive
18+
lfs: true
19+
- run: git submodule update --remote
1620

1721
- name: Deploy to Vercel
1822
id: vercel-deployment
@@ -45,6 +49,11 @@ jobs:
4549
- tag: a
4650
text: ${{ github.ref }}
4751
href: ${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref_name }}
52+
- - tag: text
53+
text: 提交作者:
54+
- tag: a
55+
text: ${{ github.actor }}
56+
href: ${{ github.server_url }}/${{ github.actor }}
4857
- - tag: text
4958
text: 预览链接:
5059
- tag: a

Dockerfile

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Reference: https://pnpm.io/docker#example-1-build-a-bundle-in-a-docker-container
2-
3-
FROM node:18-slim AS base
1+
FROM node:20-slim AS base
42
RUN apt-get update && \
53
apt-get install ca-certificates curl libjemalloc-dev -y --no-install-recommends && \
64
rm -rf /var/lib/apt/lists/*
@@ -14,16 +12,15 @@ RUN corepack enable
1412
COPY . /app
1513
WORKDIR /app
1614

17-
FROM base AS prod-deps
18-
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm i -P --frozen-lockfile --ignore-scripts
19-
2015
FROM base AS build
2116
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm i --frozen-lockfile
22-
RUN pnpm build
17+
RUN CI=true pnpm build
2318

2419
FROM base
25-
COPY --from=prod-deps /app/node_modules ./node_modules
2620
COPY --from=build /app/public ./public
27-
COPY --from=build /app/.next ./.next
21+
COPY --from=build /app/.next/static ./.next/static
22+
COPY --from=build /app/.next/standalone ./
2823
EXPOSE 3000
29-
CMD ["npm", "start"]
24+
ENV PORT=3000
25+
ENV HOSTNAME="0.0.0.0"
26+
CMD ["node", "server.js"]

components/NotFoundCard.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ErrorProps } from 'next/error';
2+
import { FC } from 'react';
3+
4+
import { i18n } from '../models/Translation';
5+
6+
export const NotFoundCard: FC<ErrorProps> = ({ title }) =>
7+
i18n.currentLanguage.startsWith('zh') ? (
8+
<script
9+
src="//cdn.dnpw.org/404/v1.min.js"
10+
// @ts-ignore
11+
jumptarget="/"
12+
jumptime="-1"
13+
error={title}
14+
/>
15+
) : (
16+
<iframe
17+
className="w-100 vh-100 border-0"
18+
src="https://notfound-static.fwebservices.be/en/404?key=66abb751ed312"
19+
/>
20+
);

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/basic-features/typescript for more information.
5+
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.

next.config.mjs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { withSentryConfig } from '@sentry/nextjs';
22
import setPWA from 'next-pwa';
3+
// @ts-ignore
34
import withLess from 'next-with-less';
45
import webpack from 'webpack';
56

6-
const { NODE_ENV, SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT } = process.env;
7+
const { NODE_ENV, CI, SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT } =
8+
process.env;
79
const isDev = NODE_ENV === 'development';
810

911
const withPWA = setPWA({
@@ -13,11 +15,9 @@ const withPWA = setPWA({
1315
disable: isDev,
1416
});
1517

16-
/**
17-
* @type {import('next').NextConfig}
18-
*/
19-
const nextConfig = withPWA(
20-
withLess({
18+
const nextConfig = withLess(
19+
withPWA({
20+
output: CI ? 'standalone' : undefined,
2121
webpack: config => {
2222
config.plugins.push(
2323
new webpack.NormalModuleReplacementPlugin(/^node:/, resource => {
@@ -31,18 +31,10 @@ const nextConfig = withPWA(
3131

3232
export default isDev || !SENTRY_AUTH_TOKEN
3333
? nextConfig
34-
: withSentryConfig(
35-
{
36-
...nextConfig,
37-
sentry: {
38-
transpileClientSDK: true,
39-
autoInstrumentServerFunctions: false,
40-
},
41-
},
42-
{
43-
org: SENTRY_ORG,
44-
project: SENTRY_PROJECT,
45-
authToken: SENTRY_AUTH_TOKEN,
46-
silent: true,
47-
},
48-
);
34+
: withSentryConfig(nextConfig, {
35+
autoInstrumentServerFunctions: false,
36+
org: SENTRY_ORG,
37+
project: SENTRY_PROJECT,
38+
authToken: SENTRY_AUTH_TOKEN,
39+
silent: true,
40+
});

package.json

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,58 @@
44
"description": "React project scaffold based on TypeScript, Next.js, Bootstrap & Workbox.",
55
"private": true,
66
"dependencies": {
7-
"@sentry/nextjs": "^8.9.2",
7+
"@sentry/nextjs": "^8.28.0",
88
"classnames": "^2.5.1",
9-
"file-type": "^19.0.0",
9+
"file-type": "^19.4.1",
1010
"idea-react": "^2.0.0-rc.2",
11-
"koajax": "^1.1.2",
11+
"koajax": "^3.0.1",
1212
"less": "^4.2.0",
1313
"less-loader": "^12.2.0",
14-
"mobx": "^6.12.4",
15-
"mobx-github": "^0.3.2",
14+
"mobx": "^6.13.1",
15+
"mobx-github": "^0.3.4",
1616
"mobx-i18n": "^0.5.0",
17-
"mobx-lark": "^2.0.0-rc.1",
17+
"mobx-lark": "^2.0.0-rc.2",
1818
"mobx-react": "^9.1.1",
19-
"mobx-restful": "^0.7.0-rc.0",
20-
"mobx-restful-table": "^2.0.0-rc.1",
21-
"next": "^14.2.4",
19+
"mobx-restful": "^1.0.1",
20+
"mobx-restful-table": "^2.0.0",
21+
"next": "^14.2.8",
2222
"next-pwa": "~5.6.0",
23-
"next-ssr-middleware": "^0.8.1",
23+
"next-ssr-middleware": "^0.8.7",
2424
"next-with-less": "^3.0.1",
2525
"react": "^18.3.1",
26-
"react-bootstrap": "^2.10.2",
26+
"react-bootstrap": "^2.10.4",
2727
"react-dom": "^18.3.1",
2828
"react-marked-renderer": "^2.0.1",
2929
"web-utility": "^4.4.0",
30-
"webpack": "^5.92.0"
30+
"webpack": "^5.94.0"
3131
},
3232
"devDependencies": {
3333
"@babel/plugin-proposal-decorators": "^7.24.7",
34-
"@babel/plugin-transform-typescript": "^7.24.7",
34+
"@babel/plugin-transform-typescript": "^7.25.2",
3535
"@babel/preset-react": "^7.24.7",
36-
"@types/node": "^18.19.36",
37-
"@types/react": "^18.3.3",
36+
"@types/next-pwa": "^5.6.9",
37+
"@types/node": "^20.16.5",
38+
"@types/react": "^18.3.5",
3839
"eslint": "^8.57.0",
39-
"eslint-config-next": "^14.2.4",
40+
"eslint-config-next": "^14.2.8",
4041
"eslint-config-prettier": "^9.1.0",
41-
"eslint-plugin-simple-import-sort": "^12.1.0",
42-
"husky": "^9.0.11",
43-
"lint-staged": "^15.2.7",
44-
"prettier": "^3.3.2",
45-
"typescript": "~5.4.5"
42+
"eslint-plugin-simple-import-sort": "^12.1.1",
43+
"husky": "^9.1.5",
44+
"lint-staged": "^15.2.10",
45+
"prettier": "^3.3.3",
46+
"typescript": "~5.5.4"
47+
},
48+
"resolutions": {
49+
"native-file-system-adapter": "npm:@tech_query/native-file-system-adapter@^3.0.1"
4650
},
4751
"prettier": {
4852
"singleQuote": true,
4953
"trailingComma": "all",
5054
"arrowParens": "avoid"
5155
},
5256
"lint-staged": {
53-
"*.{html,md,less,json,yml,js,ts,tsx}": "prettier --write",
54-
"*.{js,jsx,ts,tsx}": "eslint --fix"
57+
"*.{html,md,less,json,yml,js,mjs,ts,tsx}": "prettier --write",
58+
"*.{js,mjs,ts,tsx}": "eslint --fix"
5559
},
5660
"scripts": {
5761
"prepare": "husky",
@@ -60,7 +64,7 @@
6064
"export": "next build && next export",
6165
"start": "next start",
6266
"lint": "next lint",
63-
"test": "lint-staged && npm run lint",
67+
"test": "lint-staged && npm run lint && tsc --noEmit",
6468
"pack-image": "docker build -t idea2app/web-server .",
6569
"container": "docker rm -f web-server && docker run --name web-server -p 3000:3000 -d idea2app/web-server"
6670
}

pages/_app.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ configure({ enforceActions: 'never' });
2121
enableStaticRendering(isServer());
2222

2323
globalThis.addEventListener?.('unhandledrejection', ({ reason }) => {
24-
var { message, statusText } = reason as HTTPError;
24+
var { message, response } = reason as HTTPError;
25+
const { statusText, body } = response || {};
2526

26-
message = statusText || message;
27+
message = body?.message || statusText || message;
2728

2829
if (message) alert(message);
2930
});

pages/_error.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
import * as Sentry from '@sentry/nextjs';
2+
import { parseCookie, parseLanguageHeader } from 'mobx-i18n';
23
import type { NextPage } from 'next';
34
import type { ErrorProps } from 'next/error';
45
import Error from 'next/error';
56

6-
const CustomErrorComponent: NextPage<ErrorProps> = ({ statusCode }) => (
7-
<Error statusCode={statusCode} />
7+
import { NotFoundCard } from '../components/NotFoundCard';
8+
import { i18n } from '../models/Translation';
9+
10+
const CustomErrorComponent: NextPage<ErrorProps> = props => (
11+
<>
12+
<Error {...props} />
13+
14+
<NotFoundCard {...props} />
15+
</>
816
);
17+
const enableSentry =
18+
process.env.NODE_ENV === 'development' || !process.env.SENTRY_AUTH_TOKEN;
919

1020
CustomErrorComponent.getInitialProps = async contextData => {
11-
await Sentry.captureUnderscoreErrorException(contextData);
21+
const { 'accept-language': acceptLanguage, cookie = '' } =
22+
contextData.req!.headers;
23+
const { language } = parseCookie(cookie),
24+
languages = parseLanguageHeader(acceptLanguage || '');
25+
26+
await i18n.loadLanguages([language, ...languages].filter(Boolean));
27+
28+
if (enableSentry) await Sentry.captureUnderscoreErrorException(contextData);
1229

1330
return Error.getInitialProps(contextData);
1431
};
1532

16-
export default process.env.NODE_ENV === 'development' ||
17-
!process.env.SENTRY_AUTH_TOKEN
18-
? Error
19-
: CustomErrorComponent;
33+
export default CustomErrorComponent;

pages/api/core.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export function safeAPI(handler: NextAPI): NextAPI {
1919
res.status(400);
2020
return res.send({ message: (error as Error).message });
2121
}
22-
let { message, status, body } = error;
22+
const { message, response } = error;
23+
let { status, body } = response;
2324

2425
res.status(status);
2526
res.statusMessage = message;

pages/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { GitRepository } from 'mobx-github';
12
import { observer } from 'mobx-react';
23
import { InferGetServerSidePropsType } from 'next';
34
import { cache, compose, errorLogger, translator } from 'next-ssr-middleware';
@@ -34,7 +35,9 @@ export const getServerSideProps = compose(
3435
return {
3536
props: {
3637
projects: JSON.parse(JSON.stringify(projects)) as Project[],
37-
repositories,
38+
repositories: JSON.parse(
39+
JSON.stringify(repositories),
40+
) as GitRepository[],
3841
partners,
3942
members: members.filter(
4043
({ github, position, summary }) => github && position && summary,

0 commit comments

Comments
 (0)