How to get the forge tunnel working in a mono repo

Using the Forge tunnel within a mono repo causes a few issues as everything is built in a Docker container but the container only has access to the current working directory so you can’t access the other packages in the mono repo.

The Forge tunnel bind mounts your app folder into /app but this can be modified using the un-documented environment variable CUR_WORK_APP_DIR. You can see how the variable works here:

getVolumeOptions() {
        const options = [`-v=${CUR_WORK_APP_DIR || process.cwd()}:/app:cached`];
        if (process.env.FORGE_DEV_DOCKER_TUNNEL) {
            options.push(`-v=${(0, path_1.join)(__dirname, '../../../..')}:/monorepo:cached`);
        return options;

So if you set CUR_WORK_APP_DIR to the root of your mono repo your whole mono repo will be bind mounted into the app folder.

Unfortunately the tunnel expects your Forge app to be in /app so you need to patch @forge/cli to change the workdir to the actual path inside your mono repo where the forge app is.

My patch to @forge/cli looks like this:

diff --git a/out/service/tunnel-service.js b/out/service/tunnel-service.js
index fdb1a03b50f3fb0b6af94a978e9b9ae0021f9e23..eb8602c2879969a3a484b4deac3084238d65b646 100644
--- a/out/service/tunnel-service.js
+++ b/out/service/tunnel-service.js
@@ -161,6 +161,11 @@ class TunnelServiceBase {
+        if(process.env.RUN_WORK_DIR){
+            options.push(`--workdir=${process.env.RUN_WORK_DIR}`);
+        }
         return options;

And I run the tunnel using the following command: CUR_WORK_APP_DIR=$(realpath ../../) RUN_WORK_DIR=/app/packages/stp-forge forge tunnel where my app is in the packages/stp-forge folder in the mono repo.

I understand this isn’t exactly simple or supported but thought it might help someone out!

1 Like

@tbinna has done some cool work with mono repos which might be of interest Forge monorepo apps

Cheers Adam,

I’ll take a look!