@@ -3,6 +3,14 @@ const crypto = require('crypto');
3
3
const { api } = require ( '@replit/protocol' ) ;
4
4
const paseto = require ( './paseto' ) ;
5
5
6
+ let cluster = 'mark' ;
7
+ if ( ! process . env . USER_KEY_ID && ! process . env . USER_PRIVATE_KEY ) {
8
+ process . env . USER_KEY_ID = 'dev' ;
9
+ process . env . USER_PRIVATE_KEY =
10
+ 'h/Qn2Wtu0bq85i3EF17r/diy4xNdYAMkCgHxLmu3xG+ifQWRKYQL5x7jRX1VzhAAFdLHpNej6WGn31voprSCug==' ;
11
+ cluster = 'development' ;
12
+ }
13
+
6
14
if ( ! process . env . USER_KEY_ID || ! process . env . USER_PRIVATE_KEY ) {
7
15
throw new Error ( 'Expected USER_KEY_ID and USER_PRIVATE_KEY in ENV' ) ;
8
16
}
@@ -23,9 +31,9 @@ ${keyData.toString('base64')}
23
31
function genConnectionMetadata ( options ) {
24
32
const now = Date . now ( ) ;
25
33
26
- const restrictNetwork = ! ! options ? .restrictNetwork ;
34
+ const restrictNetwork = ! ! ( options && options . restrictNetwork ) ;
27
35
28
- const repl = options ? .repl || {
36
+ const repl = ( options && options . repl ) || {
29
37
id : `testing-crosis-${ Math . random ( ) . toString ( 36 ) . split ( '.' ) [ 1 ] } ` ,
30
38
language : 'bash' ,
31
39
slug : Math . random ( ) . toString ( 36 ) . slice ( 2 ) ,
@@ -44,7 +52,7 @@ function genConnectionMetadata(options) {
44
52
exp : {
45
53
seconds : Math . floor ( now / 1000 ) + 60 * 60 ,
46
54
} ,
47
- cluster : 'global' ,
55
+ cluster,
48
56
persistence : api . repl . Persistence . NONE ,
49
57
format : api . ReplToken . WireFormat . PROTOBUF ,
50
58
repl,
@@ -74,12 +82,23 @@ function genConnectionMetadata(options) {
74
82
) ,
75
83
) ;
76
84
85
+ const clusterMetadata =
86
+ cluster === 'development'
87
+ ? {
88
+ gurl : 'ws://localhost:4560' ,
89
+ conmanURL : 'http://localhost:4560' ,
90
+ dotdevHostname : `http://${ repl . id } -00-replittesting.${ cluster } .replit.localhost:8081` ,
91
+ }
92
+ : {
93
+ gurl : `wss://eval.${ cluster } .replit.com` ,
94
+ conmanURL : `https://eval.${ cluster } .replit.com` ,
95
+ dotdevHostname : `https://${ repl . id } -00-replittesting.${ cluster } .replit.dev` ,
96
+ } ;
97
+
77
98
return {
78
99
token : encodedToken ,
79
- gurl : 'wss://eval.global.replit.com' ,
80
- conmanURL : 'https://eval.global.replit.com' ,
81
100
repl,
82
- dotdevHostname : `https:// ${ repl . id } -00-replittesting.gloval.replit.dev` ,
101
+ ... clusterMetadata ,
83
102
} ;
84
103
}
85
104
0 commit comments