File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { loadEnv } from "vite" ;
2
+ import fs from "fs" ;
3
+ import { homedir } from "os" ;
4
+ import { resolve } from "path" ;
5
+
6
+ export function getValetHome ( ) {
7
+ let valetPath = resolve ( homedir ( ) , ".config/valet" ) ;
8
+ if ( fs . existsSync ( valetPath ) ) {
9
+ return valetPath ;
10
+ }
11
+
12
+ valetPath = resolve ( homedir ( ) , ".valet" ) ;
13
+ if ( fs . existsSync ( valetPath ) ) {
14
+ return valetPath ;
15
+ }
16
+
17
+ return null ;
18
+ }
19
+
20
+ // Variation of https://freek.dev/2276-making-vite-and-valet-play-nice-together
21
+ export function detectServerConfig ( mode ) {
22
+ const valetPath = getValetHome ( ) ;
23
+ if ( ! valetPath ) {
24
+ return ;
25
+ }
26
+
27
+ const host = loadEnv ( mode , process . cwd ( ) ) . VITE_HOST ?? "localhost" ;
28
+ let keyPath = resolve ( valetPath , `Certificates/${ host } .key` ) ;
29
+ let certificatePath = resolve ( valetPath , `Certificates/${ host } .crt` ) ;
30
+
31
+ if ( ! fs . existsSync ( keyPath ) ) {
32
+ return ;
33
+ }
34
+
35
+ if ( ! fs . existsSync ( certificatePath ) ) {
36
+ return ;
37
+ }
38
+
39
+ return {
40
+ host,
41
+ port : 3000 ,
42
+ https : {
43
+ key : fs . readFileSync ( keyPath ) ,
44
+ cert : fs . readFileSync ( certificatePath ) ,
45
+ } ,
46
+ } ;
47
+ }
You can’t perform that action at this time.
0 commit comments