Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support pwa, add bundle-analyzer #17

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#############################################
############ OIDC Server Configs ############
#############################################

# oidc server url
OIDC_SERVER_URL=[oidc_server_url]/oidc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要说明下,我们把请求中写死的 /oidc 去掉是因为 oidc_server_url 本身是带 /oidc 的,不是 oidc_server_url 地址后面要加个 /oidc,这里可以在备注里加个例子,比如 https://kubeagi.com/oidc


# oidc server client id && secret
CLIENT_ID=client_id
CLIENT_SECRET=client_secret

# origin
CLIENT_ORIGIN=http://localhost:3000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

origin 本身是可以取到的,不需要配置,这个变量之前就有点儿犹豫是否必要,留下的主要考虑是:

  • 后端渲染时可能取不到正确的取值(部署环境代理等问题),不过也可以由浏览器端获取到然后通过 query 带给后端
  • 不过这就带来了第二个问题,portal 部署后,我们可以通过域名或者 ip 的方式访问,这样的话获取到的 origin 不是固定的,可能会由于 oidc 未配置相关 callback 地址导致不同方式的访问实际表现不一致

@nkwangleiGIT 不考虑上述情况的话,这个变量可以省略

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经去掉, 服务端改为从 next/headers 中获取, 客户端 location.origin

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ test-output

# dev
.env.development
.env.production

# misc
*.pem
/cert/*.crt
/cert/*.key

# local env files
.env*.local
Expand All @@ -66,3 +69,5 @@ next-env.d.ts

# misc
# add other ignore file below
public/*.js
public/*.js.map
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ bun dev

Open <http://localhost:3000> with your browser to see the result.

## Development OIDC 配置
## .env 配置 (示例: ./.env.example)

根目录新建 `.env.development`
### 开发模式

```
OIDC_SERVER_URL=[OIDC_SERVER_URL]
CLIENT_ID=[CLIENT_ID]
CLIENT_SECRET=[CLIENT_SECRET]
CLIENT_ORIGIN=[CLIENT_ORIGIN]
cp .env.example .env.development
```

复制并重命名为 .env.development, 修改 oidc(必须) 等参数

### 生产模式

```
cp .env.example .env.production
```

复制并重命名为 .env.production, 修改 oidc(必须) 等参数
27 changes: 15 additions & 12 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import nextPWA from '@ducanh2912/next-pwa';
import analyzer from '@next/bundle-analyzer';

import config from './src/config/oidc.mjs';
const oidcUrl = config.server.url;
const isProd = process.env.NODE_ENV === 'production';

const withBundleAnalyzer = analyzer({
enabled: process.env.ANALYZE === 'true',
});

const withPWA = nextPWA({
dest: 'public',
register: true,
workboxOptions: {
skipWaiting: true,
},
});

const nextConfig = {
compress: isProd,
typescript: {
Expand All @@ -26,15 +38,6 @@ const nextConfig = {
},
reactStrictMode: true,
transpilePackages: ['antd', '@ant-design', 'antd-style', '@lobehub/ui', 'antd-mobile'],
// async rewrites() {
// return [
// {
// source: '/oidc/token',
// destination: `${oidcUrl}/oidc/token`,
// secure: false,
// },
// ]
// },
webpack: (config) => {
config.experiments = {
asyncWebAssembly: true,
Expand All @@ -59,4 +62,4 @@ const nextConfig = {
},
}

export default nextConfig
export default isProd ? withBundleAnalyzer(withPWA(nextConfig)) : nextConfig;
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"version": "0.1.0",
"scripts": {
"build": "next build",
"build:analyze": "cross-env ANALYZE=true next build",
"dev": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 next dev",
"dev-https": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 next dev --experimental-https --experimental-https-key ./cert/key.pem --experimental-https-cert ./cert/cert.pem",
"dev:https": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 next dev --experimental-https --experimental-https-key ./cert/key.pem --experimental-https-cert ./cert/cert.pem",
"lint": "npm run lint:es && npm run lint:style",
"lint-fix": "npm run lint-fix:es && npm run lint-fix:style",
"lint-fix:es": "eslint --ext .jsx,.js,.tsx,.ts src --fix",
Expand All @@ -13,7 +14,8 @@
"lint:style": "stylelint \"{src,tests}/**/*.{css,less,js,jsx,ts,tsx}\"",
"prepare": "husky install",
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
"start": "next start"
"start": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 next start",
"start:https": "cross-env NODE_ENV=production NODE_TLS_REJECT_UNAUTHORIZED=0 node server.mjs"
},
"lint-staged": {
"*.md": [
Expand Down Expand Up @@ -60,6 +62,8 @@
"ua-parser-js": "2.0.0-alpha.2"
},
"devDependencies": {
"@ducanh2912/next-pwa": "^10.2.2",
"@next/bundle-analyzer": "^14.1.0",
"@types/mdx": "^2.0.10",
"@types/node": "^20",
"@types/query-string": "^6.3.0",
Expand All @@ -77,7 +81,8 @@
"remark": "^15.0.1",
"remark-cli": "^12.0.0",
"stylelint": "^15",
"typescript": "^5"
"typescript": "^5",
"webpack": "^5.89.0"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
Loading