From 462e86b9a075ddc1979c75fc0c0c29737b53caf6 Mon Sep 17 00:00:00 2001 From: DarkSky Date: Sat, 7 Jan 2023 17:01:10 +0800 Subject: [PATCH] feat: improve scripts --- package.json | 3 +- packages/app/next.config.js | 57 +++++++++++++++++-------------------- packages/app/package.json | 1 - 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 1abcf66a9..7c9ac38d1 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "license": "MPL-2.0", "scripts": { "dev": "pnpm --filter=!@affine/app build && pnpm --filter @affine/app dev", - "dev:ac": "pnpm --filter=!@affine/app build && pnpm --filter @affine/app dev:ac", + "dev:ac": "pnpm --filter=!@affine/app build && NODE_API_SERVER=ac pnpm --filter @affine/app dev", + "dev:local": "pnpm --filter=!@affine/app build && NODE_API_SERVER=local pnpm --filter @affine/app dev", "build": " pnpm --filter=!@affine/app build && pnpm --filter!=@affine/datacenter -r build", "export": "pnpm --filter @affine/app export", "start": "pnpm --filter @affine/app start", diff --git a/packages/app/next.config.js b/packages/app/next.config.js index 10da79648..df91a7010 100644 --- a/packages/app/next.config.js +++ b/packages/app/next.config.js @@ -9,6 +9,27 @@ const EDITOR_VERSION = enableDebugLocal ? 'local-version' : dependencies['@blocksuite/editor']; +const profileTarget = { + ac: '100.85.73.88:12001', + dev: '100.85.73.88:12001', + local: '127.0.0.1:3000', +}; + +const getRedirectConfig = profile => { + const target = profileTarget[profile || 'dev'] || profileTarget['dev']; + + return [ + [ + { source: '/api/:path*', destination: `http://${target}/api/:path*` }, + { + source: '/collaboration/:path*', + destination: `http://${target}/collaboration/:path*`, + }, + ], + target, + ]; +}; + /** @type {import('next').NextConfig} */ const nextConfig = { productionBrowserSourceMaps: true, @@ -36,38 +57,12 @@ const nextConfig = { images: { unoptimized: true, }, - // XXX not test yet rewrites: async () => { - if (process.env.NODE_API_SERVER === 'ac') { - let destinationAC = 'http://100.85.73.88:12001/api/:path*'; - printer.info('API request proxy to [AC Server] ' + destinationAC); - return [ - { - source: '/api/:path*', - destination: destinationAC, - }, - { - source: '/collaboration/:path*', - destination: 'http://localhost:3000/collaboration/:path*', - }, - ]; - } else { - let destinationStandard = 'http://100.77.180.48:11001/api/:path*'; - printer.info( - 'API request proxy to [Standard Server] ' + destinationStandard - ); - - return [ - { - source: '/api/:path*', - destination: destinationStandard, - }, - { - source: '/collaboration/:path*', - destination: 'http://localhost:3000/collaboration/:path*', - }, - ]; - } + const [profile, desc] = getRedirectConfig(process.env.NODE_API_SERVER); + printer.info( + `API request proxy to [${process.env.NODE_API_SERVER} Server]: ` + desc + ); + return profile; }, basePath: process.env.BASE_PATH, }; diff --git a/packages/app/package.json b/packages/app/package.json index 9dac686ae..3ba74e271 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -3,7 +3,6 @@ "version": "0.3.1", "scripts": { "dev": "next dev -p 8080", - "dev:ac": "NODE_API_SERVER=ac next dev -p 8080", "build": "next build", "export": "next export", "start": "next start",