File tree Expand file tree Collapse file tree 8 files changed +1168
-13
lines changed Expand file tree Collapse file tree 8 files changed +1168
-13
lines changed Original file line number Diff line number Diff line change 1
1
API_BASE_URL = http://localhost:3000
2
2
DEBUG = true
3
+ CA_KEY_PATH = ./certs/key.pem
4
+ CA_CERT_PATH = ./certs/cert.pem
3
5
4
6
# filesystem
5
7
STORAGE_DRIVER = filesystem
Original file line number Diff line number Diff line change 10
10
.data
11
11
.idea
12
12
.DS_Store
13
- tests /temp /
13
+ tests /temp /
14
+ certs /*
15
+ ! certs /.gitkeep
Original file line number Diff line number Diff line change 1
1
import { z } from 'zod'
2
2
3
3
const booleanSchema = z . string ( ) . transform ( ( v ) => v . toLowerCase ( ) === 'true' )
4
+ const portSchema = z . coerce . number ( ) . int ( ) . min ( 1 ) . max ( 65_535 )
4
5
5
6
const envSchema = z . object ( {
6
7
ENABLE_DIRECT_DOWNLOADS : booleanSchema . default ( 'false' ) ,
@@ -9,6 +10,10 @@ const envSchema = z.object({
9
10
STORAGE_DRIVER : z . string ( ) . toLowerCase ( ) . default ( 'filesystem' ) ,
10
11
DB_DRIVER : z . string ( ) . toLowerCase ( ) . default ( 'sqlite' ) ,
11
12
DEBUG : booleanSchema . default ( 'false' ) ,
13
+ PROXY_PORT : portSchema . default ( 8000 ) ,
14
+ NITRO_PORT : portSchema . default ( 3000 ) ,
15
+ CA_KEY_PATH : z . string ( ) ,
16
+ CA_CERT_PATH : z . string ( ) ,
12
17
TEMP_DIR : z . string ( ) . default ( tmpdir ( ) ) ,
13
18
} )
14
19
Original file line number Diff line number Diff line change
1
+ import mockttp from 'mockttp'
2
+ import { ENV } from './env'
3
+ import { logger } from './logger'
4
+
5
+ export async function initializeProxy ( ) {
6
+ const port = ENV . PROXY_PORT
7
+ logger . info ( `Starting proxy server on port ${ port } ...` )
8
+
9
+ // generate ca with `openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365`
10
+ const server = mockttp . getLocal ( {
11
+ https : {
12
+ keyPath : ENV . CA_KEY_PATH ,
13
+ certPath : ENV . CA_CERT_PATH ,
14
+ tlsPassthrough : [
15
+ {
16
+ hostname : 'broker.actions.githubusercontent.com' ,
17
+ } ,
18
+ ] ,
19
+ } ,
20
+ } )
21
+
22
+ await server
23
+ . forAnyRequest ( )
24
+ . withUrlMatching (
25
+ / ( t w i r p \/ g i t h u b \. a c t i o n s \. r e s u l t s \. a p i \. v 1 \. C a c h e S e r v i c e ) | ( _ a p i s \/ a r t i f a c t c a c h e ) / ,
26
+ )
27
+ . thenForwardTo ( `http://localhost:${ ENV . NITRO_PORT } ` )
28
+
29
+ await server . forUnmatchedRequest ( ) . thenPassThrough ( )
30
+
31
+ await server . start ( port )
32
+ }
Original file line number Diff line number Diff line change 35
35
"execa" : " ^9.5.2" ,
36
36
"h3" : " ^1.14.0" ,
37
37
"kysely" : " ^0.27.5" ,
38
+ "mockttp" : " ^3.16.0" ,
38
39
"mysql2" : " ^3.12.0" ,
39
40
"nitropack" : " ^2.10.4" ,
40
41
"pg" : " ^8.13.1" ,
Original file line number Diff line number Diff line change @@ -3,12 +3,14 @@ import { H3Error } from 'h3'
3
3
import { initializeDatabase , useDB } from '~/lib/db'
4
4
import { ENV } from '~/lib/env'
5
5
import { logger } from '~/lib/logger'
6
+ import { initializeProxy } from '~/lib/proxy'
6
7
import { initializeStorage , useStorageAdapter } from '~/lib/storage'
7
8
8
9
export default defineNitroPlugin ( async ( nitro ) => {
9
10
const version = useRuntimeConfig ( ) . version
10
11
logger . info ( `🚀 Starting GitHub Actions Cache Server (${ version } )` )
11
12
13
+ await initializeProxy ( )
12
14
await initializeDatabase ( )
13
15
await initializeStorage ( )
14
16
You can’t perform that action at this time.
0 commit comments