From 688f1dd9caf5c8c522877e012dff5b5041f8f2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dinh=20=C2=B7=20divn=2Edev?= Date: Sat, 2 Dec 2023 11:03:22 +0700 Subject: [PATCH] handle @web deployment --- @api/wrangler.toml | 8 ++++---- @web/.env.example | 1 - @web/.env.local | 1 + @web/.env.preview | 1 + @web/.env.production | 1 + @web/.gitignore | 3 +-- @web/app/page.tsx | 1 + @web/package.json | 5 +++-- package.json | 1 + pnpm-lock.yaml | 44 ++++++++++++-------------------------------- 10 files changed, 25 insertions(+), 41 deletions(-) delete mode 100644 @web/.env.example create mode 100644 @web/.env.local create mode 100644 @web/.env.preview create mode 100644 @web/.env.production diff --git a/@api/wrangler.toml b/@api/wrangler.toml index b5275a1..0388c4e 100644 --- a/@api/wrangler.toml +++ b/@api/wrangler.toml @@ -14,12 +14,12 @@ WEB_URL = "http://localhost:3000" # ------------------------------------------------------------------------------------------------------------ # [env.preview.route] -# pattern = "preview.api.dinstack.ai" +# pattern = "preview.api.example.com" # custom_domain = true [env.preview.vars] WORKER_ENV = "development" -WEB_URL = "https://preview.dinstack.ai" +WEB_URL = "https://preview.example.com" # ------------------------------------------------------------------------------------------------------------ @@ -27,11 +27,11 @@ WEB_URL = "https://preview.dinstack.ai" logpush = true # [env.production.route] -# pattern = "api.dinstack.ai" +# pattern = "api.example.com" # custom_domain = true [env.production.vars] WORKER_ENV = "production" -WEB_URL = "https://app.dinstack.ai" +WEB_URL = "https://app.example.com" # ------------------------------------------------------------------------------------------------------------ diff --git a/@web/.env.example b/@web/.env.example deleted file mode 100644 index fd2fa8e..0000000 --- a/@web/.env.example +++ /dev/null @@ -1 +0,0 @@ -API_URL= \ No newline at end of file diff --git a/@web/.env.local b/@web/.env.local new file mode 100644 index 0000000..f9feddb --- /dev/null +++ b/@web/.env.local @@ -0,0 +1 @@ +NEXT_PUBLIC_API_URL=http://localhost:8000 \ No newline at end of file diff --git a/@web/.env.preview b/@web/.env.preview new file mode 100644 index 0000000..63175ae --- /dev/null +++ b/@web/.env.preview @@ -0,0 +1 @@ +NEXT_PUBLIC_API_URL=https://preview.api.example.com diff --git a/@web/.env.production b/@web/.env.production new file mode 100644 index 0000000..6c01aec --- /dev/null +++ b/@web/.env.production @@ -0,0 +1 @@ +NEXT_PUBLIC_API_URL=https://api.example.com diff --git a/@web/.gitignore b/@web/.gitignore index 6512345..39d8122 100644 --- a/@web/.gitignore +++ b/@web/.gitignore @@ -26,8 +26,7 @@ yarn-debug.log* yarn-error.log* # local env files -.env* -!.env.example +# .env*.local # vercel .vercel diff --git a/@web/app/page.tsx b/@web/app/page.tsx index 9110c0c..5abbea7 100644 --- a/@web/app/page.tsx +++ b/@web/app/page.tsx @@ -6,6 +6,7 @@ export default function Home() { const { status, data } = api.ping.useQuery() return (
+ {process.env.NEXT_PUBLIC_API_URL} {status} {JSON.stringify(data)} diff --git a/@web/package.json b/@web/package.json index 3fea2aa..bd21a6c 100644 --- a/@web/package.json +++ b/@web/package.json @@ -4,9 +4,10 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build", "preview": "next build && pnpx serve@latest out", - "typecheck": "tsc --noEmit" + "typecheck": "tsc --noEmit", + "deploy:preview": "env-cmd -f .env.preview next build && wrangler pages deploy --project-name=dinstack-web-preview --branch=main ./dist", + "deploy:production": "env-cmd -f .env.production next build && wrangler pages deploy --project-name=dinstack-web-production --branch=main ./dist" }, "dependencies": { "@dinstack/ui": "workspace:^", diff --git a/package.json b/package.json index f0766e3..bd6531d 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@typescript-eslint/eslint-plugin": "^6.13.1", "@typescript-eslint/parser": "^6.13.1", + "env-cmd": "^10.1.0", "eslint": "^8.55.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-react": "^7.33.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 390462d..16d26bc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: '@typescript-eslint/parser': specifier: ^6.13.1 version: 6.13.1(eslint@8.55.0)(typescript@5.3.2) + env-cmd: + specifier: ^10.1.0 + version: 10.1.0 eslint: specifier: ^8.55.0 version: 8.55.0 @@ -32,9 +35,6 @@ importers: prettier: specifier: ^3.1.0 version: 3.1.0 - prettier-plugin-astro: - specifier: ^0.12.2 - version: 0.12.2 tsc-alias: specifier: ^1.8.8 version: 1.8.8 @@ -249,10 +249,6 @@ packages: engines: {node: '>=10'} dev: true - /@astrojs/compiler@1.8.2: - resolution: {integrity: sha512-o/ObKgtMzl8SlpIdzaxFnt7SATKPxu4oIP/1NL+HDJRzxfJcAkOTAb/ZKMRyULbz4q+1t2/DAebs2Z1QairkZw==} - dev: true - /@babel/code-frame@7.23.5: resolution: {integrity: sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==} engines: {node: '>=6.9.0'} @@ -3118,6 +3114,15 @@ packages: resolution: {integrity: sha512-KD6CWjf1BnQG+NsXuyiTDDT1eV13sKuYsOUioXkQweYTQIbgHkXPry9K7M+7cKtYHnSUPitVaLrXYB1jTkkYrw==} dev: true + /env-cmd@10.1.0: + resolution: {integrity: sha512-mMdWTT9XKN7yNth/6N6g2GuKuJTsKMDHlQFUDacb/heQRRWOTIZ42t1rMHnQu4jYxU1ajdTeJM+9eEETlqToMA==} + engines: {node: '>=8.0.0'} + hasBin: true + dependencies: + commander: 4.1.1 + cross-spawn: 7.0.3 + dev: true + /es-abstract@1.22.3: resolution: {integrity: sha512-eiiY8HQeYfYH2Con2berK+To6GrK2RxbPawDkGq4UiCQQfZHb6wX9qQqkbpPqaxQFcl8d9QzZqo0tGE0VcrdwA==} engines: {node: '>= 0.4'} @@ -4633,15 +4638,6 @@ packages: engines: {node: '>= 0.8.0'} dev: true - /prettier-plugin-astro@0.12.2: - resolution: {integrity: sha512-1OXSEht27zrnX7rCa0bEpLdspeumFW4hnj4+JzPuG5bRlSOAhD0rbXBNZfRD9q0Qbr00EcCcnjd6k6M8q+GfTA==} - engines: {node: ^14.15.0 || >=16.0.0} - dependencies: - '@astrojs/compiler': 1.8.2 - prettier: 3.1.0 - sass-formatter: 0.7.8 - dev: true - /prettier@3.1.0: resolution: {integrity: sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==} engines: {node: '>=14'} @@ -4881,10 +4877,6 @@ packages: queue-microtask: 1.2.3 dev: true - /s.color@0.0.15: - resolution: {integrity: sha512-AUNrbEUHeKY8XsYr/DYpl+qk5+aM+DChopnWOPEzn8YKzOhv4l2zH6LzZms3tOZP3wwdOyc0RmTciyi46HLIuA==} - dev: true - /safe-array-concat@1.0.1: resolution: {integrity: sha512-6XbUAseYE2KtOuGueyeobCySj9L4+66Tn6KQMOPQJrAJEowYKW/YR/MGJZl7FdydUdaFu4LYyDZjxf4/Nmo23Q==} engines: {node: '>=0.4'} @@ -4903,12 +4895,6 @@ packages: is-regex: 1.1.4 dev: true - /sass-formatter@0.7.8: - resolution: {integrity: sha512-7fI2a8THglflhhYis7k06eUf92VQuJoXzEs2KRP0r1bluFxKFvLx0Ns7c478oYGM0fPfrr846ZRWVi2MAgHt9Q==} - dependencies: - suf-log: 2.5.3 - dev: true - /scheduler@0.23.0: resolution: {integrity: sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==} dependencies: @@ -5109,12 +5095,6 @@ packages: ts-interface-checker: 0.1.13 dev: true - /suf-log@2.5.3: - resolution: {integrity: sha512-KvC8OPjzdNOe+xQ4XWJV2whQA0aM1kGVczMQ8+dStAO6KfEB140JEVQ9dE76ONZ0/Ylf67ni4tILPJB41U0eow==} - dependencies: - s.color: 0.0.15 - dev: true - /superjson@2.2.1: resolution: {integrity: sha512-8iGv75BYOa0xRJHK5vRLEjE2H/i4lulTjzpUXic3Eg8akftYjkmQDa8JARQ42rlczXyFR3IeRoeFCc7RxHsYZA==} engines: {node: '>=16'}