Skip to content

Commit 1e4df26

Browse files
committed
Fix rule parameter query API to fix Docker tunnelling on Mac/Windows
Previously Docker on Mac/Windows tunneling between containers generally didn't work, because the UI did not know that the rule parameter to proxy via the tunnel was available, as it wasn't updating in the API. The API now always returns the latest value for this. This is risky for race conditions, but that's difficult to avoid and I think it should be safe: session starts, Docker setup sychronously sets the rule parameter for the new session, while the UI must wait async for the start to be confirmed before it can request the corresponding config (which requires the port, so can't be parallelized) and read the param keys.
1 parent b5dd513 commit 1e4df26

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/api-server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const INTERCEPTOR_TIMEOUT = 1000;
112112
const buildResolvers = (
113113
config: HtkConfig,
114114
interceptors: _.Dictionary<Interceptor>,
115-
ruleParamKeys: string[],
115+
getRuleParamKeys: () => string[],
116116
eventEmitter: events.EventEmitter
117117
) => {
118118
return {
@@ -138,7 +138,7 @@ const buildResolvers = (
138138
return [`127.0.0.1:${dnsServer.address().port}`];
139139
},
140140
ruleParameterKeys: async (): Promise<String[]> => {
141-
return ruleParamKeys;
141+
return getRuleParamKeys();
142142
}
143143
},
144144

@@ -274,14 +274,14 @@ export class HttpToolkitServerApi extends events.EventEmitter {
274274

275275
private server: express.Application;
276276

277-
constructor(config: HtkConfig, ruleParamKeys: string[]) {
277+
constructor(config: HtkConfig, getRuleParamKeys: () => string[]) {
278278
super();
279279

280280
let interceptors = buildInterceptors(config);
281281

282282
const schema = makeExecutableSchema({
283283
typeDefs,
284-
resolvers: buildResolvers(config, interceptors, ruleParamKeys, this)
284+
resolvers: buildResolvers(config, interceptors, getRuleParamKeys, this)
285285
});
286286

287287
this.server = express();

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export async function runHTK(options: {
188188
configPath,
189189
authToken: options.authToken,
190190
https: httpsConfig
191-
}, standalone.ruleParameterKeys);
191+
}, () => standalone.ruleParameterKeys);
192192

193193
const updateMutex = new Mutex();
194194
apiServer.on('update-requested', () => {

0 commit comments

Comments
 (0)