From 3838537a422120346dd6f302c6b96e26a22d129f Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 7 Sep 2023 17:34:10 +0800 Subject: [PATCH] feat: support setting app api use env --- .env.example | 6 ++++++ README.md | 22 +++++++++++++--------- config/index.ts | 6 +++--- 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..49b936d --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# APP ID +NEXT_PUBLIC_APP_ID= +# APP API key +NEXT_PUBLIC_APP_KEY= +# API url prefix +NEXT_PUBLIC_API_URL= diff --git a/README.md b/README.md index 9b4ab92..11f0ff9 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,22 @@ This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). ## Config App -Config app in `config/index.ts`.Please config: -- APP_ID -- API_KEY +Create a file named `.env.local` in the current directory and copy the contents from `.env.example`. Setting the following content: +``` +# APP ID +NEXT_PUBLIC_APP_ID= +# APP API key +NEXT_PUBLIC_APP_KEY= +``` -More config: +Config more in `config/index.ts` file: ```js export const APP_INFO: AppInfo = { - "title": 'Chat APP', - "description": '', - "copyright": '', - "privacy_policy": '', - "default_language": 'zh-Hans' + title: 'Chat APP', + description: '', + copyright: '', + privacy_policy: '', + default_language: 'zh-Hans' } export const isShowPrompt = true diff --git a/config/index.ts b/config/index.ts index ef025dd..1dc745b 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,7 +1,7 @@ import type { AppInfo } from '@/types/app' -export const APP_ID = `${process.env.APP_ID}` -export const API_KEY = `${process.env.API_KEY}` -export const API_URL = `${process.env.API_URL}` +export const APP_ID = `${process.env.NEXT_PUBLIC_APP_ID}` +export const API_KEY = `${process.env.NEXT_PUBLIC_APP_KEY}` +export const API_URL = `${process.env.NEXT_PUBLIC_API_URL}` export const APP_INFO: AppInfo = { title: 'Chat APP', description: '',