Skip to content

Commit

Permalink
[add] GitHub API reverse proxy
Browse files Browse the repository at this point in the history
[optimize] update Upstream packages
  • Loading branch information
TechQuery committed Aug 22, 2024
1 parent 4b8b6ee commit 699cc5d
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
EOF
cat > .env.local <<EOF
${{ secrets.ENV_FILE }}
VERCEL_URL=hackathon.kaiyuanshe.cn
VERCEL_PROJECT_PRODUCTION_URL=hackathon.kaiyuanshe.cn
EOF
- name: Build and Push image
uses: docker/build-push-action@v3
Expand Down
45 changes: 35 additions & 10 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-ignore
import withLess from 'next-with-less';
// @ts-ignore
import setPWA from 'next-pwa';
import webpack from 'webpack';
import WP from 'webpack';

const { NODE_ENV, CI } = process.env;

Expand All @@ -11,21 +13,44 @@ const withPWA = setPWA({
disable: NODE_ENV === 'development',
});

/**
* @type {import('next').NextConfig['webpack']}
*/
const webpack = config => {
config.plugins.push(
new WP.NormalModuleReplacementPlugin(/^node:/, resource => {
resource.request = resource.request.replace(/^node:/, '');
}),
);
return config;
};

/**
* @type {import('next').NextConfig['rewrites']}
*/
const rewrites = async () => ({
beforeFiles: [
{
source: '/proxy/github.com/:path*',
destination: 'https://github.com/:path*',
},
{
source: '/proxy/raw.githubusercontent.com/:path*',
destination: 'https://raw.githubusercontent.com/:path*',
},
],
afterFiles: [],
fallback: [],
});

/** @type {import('next').NextConfig} */
export default withPWA(
withLess({
reactStrictMode: true,
output: CI && 'standalone',
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
transpilePackages: ['@sentry/browser'],

webpack: config => {
config.plugins.push(
new webpack.NormalModuleReplacementPlugin(/^node:/, resource => {
resource.request = resource.request.replace(/^node:/, '');
}),
);
return config;
},
webpack,
rewrites,
}),
);
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"echarts-jsx": "^0.5.4",
"idea-react": "^2.0.0-rc.2",
"jsonwebtoken": "^9.0.2",
"koajax": "^2.0.0-rc.1",
"koajax": "^2.0.0",
"leaflet": "^1.9.4",
"leaflet.chinatmsproviders": "^3.0.6",
"lodash": "^4.17.21",
Expand All @@ -30,15 +30,14 @@
"mobx-react-helper": "^0.3.1",
"mobx-restful": "^0.7.0-rc.0",
"mobx-restful-table": "^2.0.0-rc.1",
"next": "^14.2.5",
"next-ssr-middleware": "^0.8.2",
"next": "^14.2.6",
"next-ssr-middleware": "^0.8.7",
"open-react-map": "^0.8.0",
"react": "^18.3.1",
"react-bootstrap": "^2.10.4",
"react-bootstrap-editor": "^2.0.4",
"react-dom": "^18.3.1",
"react-leaflet": "^4.2.1",
"undici": "^6.19.7",
"web-utility": "^4.4.0"
},
"devDependencies": {
Expand All @@ -51,21 +50,21 @@
"@types/jsonwebtoken": "^9.0.6",
"@types/leaflet": "^1.9.12",
"@types/lodash": "^4.17.7",
"@types/node": "^18.19.44",
"@types/react": "^18.3.3",
"@types/node": "^18.19.45",
"@types/react": "^18.3.4",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.5",
"eslint-config-next": "^14.2.6",
"eslint-plugin-simple-import-sort": "^12.1.1",
"get-git-folder": "^0.1.2",
"husky": "^9.1.4",
"husky": "^9.1.5",
"less": "^4.2.0",
"less-loader": "^12.2.0",
"lint-staged": "^15.2.9",
"next-pwa": "^5.6.0",
"next-with-less": "^3.0.1",
"prettier": "^3.3.3",
"typescript": "~5.5.4",
"webpack": "^5.93.0"
"webpack": "^5.94.0"
},
"prettier": {
"singleQuote": true,
Expand Down
16 changes: 9 additions & 7 deletions pages/api/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ import {
JWTProps,
Middleware,
} from 'next-ssr-middleware';
import { ProxyAgent, setGlobalDispatcher } from 'undici';

import { ownClient } from '../../models/User/Session';

const { HTTP_PROXY } = process.env;

if (HTTP_PROXY) setGlobalDispatcher(new ProxyAgent(HTTP_PROXY));

export type NextAPI = (
req: NextApiRequest,
res: NextApiResponse,
Expand Down Expand Up @@ -83,9 +78,16 @@ export const jwtSigner: Middleware<DataObject, JWTProps<User>> = async (
}
};

const client_id = process.env.GITHUB_OAUTH_CLIENT_ID!,
client_secret = process.env.GITHUB_OAUTH_CLIENT_SECRET!,
{ VERCEL } = process.env;

export const ProxyBaseURL = 'https://test.hackathon.kaiyuanshe.cn/proxy';

export const githubSigner = githubOAuth2({
client_id: process.env.GITHUB_OAUTH_CLIENT_ID!,
client_secret: process.env.GITHUB_OAUTH_CLIENT_SECRET!,
rootBaseURL: VERCEL ? undefined : `${ProxyBaseURL}/github.com/`,
client_id,
client_secret,
scopes: ['user:email', 'read:user', 'public_repo', 'read:project'],
});

Expand Down
Loading

1 comment on commit 699cc5d

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for open-hackathon ready!

✅ Preview
https://open-hackathon-pp29d8kmv-techquerys-projects.vercel.app

Built with commit 699cc5d.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.