File tree Expand file tree Collapse file tree 5 files changed +49
-16
lines changed
Expand file tree Collapse file tree 5 files changed +49
-16
lines changed Original file line number Diff line number Diff line change 1+ VITE_HR_DOMAIN_BE = https://dev.back.recruitment2023.hustunique.com
Original file line number Diff line number Diff line change 1+ VITE_HR_DOMAIN_BE = /api
Original file line number Diff line number Diff line change 11import { mergeConfig , UserConfig } from 'vite' ;
22import baseConfig from './vite.config.base' ;
33
4- export default mergeConfig (
5- {
6- server : {
7- proxy : {
8- '^/api' : {
9- target : 'https://dev.back.recruitment2023.hustunique.com' ,
10- changeOrigin : true ,
11- credentials : 'include' ,
12- rewrite : ( path ) => path . replace ( / ^ \/ a p i / , '' ) ,
13- cookieDomainRewrite : {
14- '*' : 'hustunique.com' ,
15- } ,
4+ const devConfig : UserConfig = {
5+ server : {
6+ proxy : {
7+ // 将 src/constants/index.ts 中的 SERVER_DOMAIN 改为 "/api"
8+ // 通过代理解决本地调试跨域问题
9+ '^/api' : {
10+ target : 'https://dev.back.recruitment2023.hustunique.com' ,
11+ changeOrigin : true ,
12+ rewrite : ( path ) => path . replace ( / ^ \/ a p i / , '' ) ,
13+ cookieDomainRewrite : {
14+ // 返回的 cookie 的 domain 设置为 localhost
15+ '*' : 'localhost' ,
16+ } ,
17+ bypass ( req , res ) {
18+ if ( ! res ) return ;
19+
20+ // const { origin } = req.headers;
21+
22+ // 这两个 header 不对会 403,故直接删掉
23+ // 改成正确的可能更好,不过我懒
24+ delete req . headers . origin ;
25+ delete req . headers . referer ;
26+
27+ // 以下代码处理跨域情况,不过现在不跨域了所以不需要了
28+ // if (origin) {
29+ // res.setHeader('Access-Control-Allow-Headers', origin);
30+ // }
31+ // res.setHeader('Access-Control-Allow-Credentials', 'true');
1632 } ,
1733 } ,
1834 } ,
1935 } ,
20- baseConfig as UserConfig ,
21- ) ;
36+ } ;
37+
38+ export default mergeConfig ( devConfig , baseConfig as UserConfig ) ;
Original file line number Diff line number Diff line change 1- export const HR_DOMAIN_BE : string =
2- 'https://dev.back.recruitment2023.hustunique.com' ;
1+ export const HR_DOMAIN_BE : string = import . meta. env . VITE_HR_DOMAIN_BE ;
32
43export const HR_DOMAIN_FE : string = 'hr2024.hustunique.com' ;
54
Original file line number Diff line number Diff line change @@ -6,3 +6,18 @@ declare module '*.vue' {
66 const component : DefineComponent < { } , { } , any > ;
77 export default component ;
88}
9+
10+ interface ViteTypeOptions {
11+ // 添加这行代码,你就可以将 ImportMetaEnv 的类型设为严格模式,
12+ // 这样就不允许有未知的键值了。
13+ strictImportMetaEnv : unknown ;
14+ }
15+
16+ interface ImportMetaEnv {
17+ readonly VITE_HR_DOMAIN_BE : string ;
18+ // 更多环境变量...
19+ }
20+
21+ interface ImportMeta {
22+ readonly env : ImportMetaEnv ;
23+ }
You can’t perform that action at this time.
0 commit comments