Hosting Interface Builder Simulations on Your Server

We get occasional inquiries about how to host your Forio Epicenter simulations on your own web server. Here’s a short set of instructions.

Hosting Simulations Built with Flow.Js

If you are building your simulation with Flow.Js or Epicenter.Js, you can find a guide to hosting your simulations in our documentation in the article How to Host an Epicenter Project on your own Server.

Hosting Simulations Built with Interface Builder

If you’ve built your simulation with the interface builder, the process is slightly more complex, since interface builder is intended to create a complete web application. The following items below are guidelines and may need to be adjusted for your specific simulation.

Easiest Approach - Embed the Simulation in an Iframe

The easiest way to embed a Forio simulation is to use an iframe. This will display your web page with the simulation embedded inside of it. The benefits of this approach are:

  • All files are hosted on Forio Epicenter.
  • Users will not see the Forio URL, and
  • The simulation will work seamlessly without modification.
  • It will be easier to make changes to your simulation, since updates (in Epicenter) will immediately appear on your website.

To embed a simulation in an iframe, include this HTML in your web page.

(In the example below, I am using a sample simulation – which may not actually exist – with the account name “dansmith” and the simulation name “supplychainsim”.

<iframe src = "https://forio.com/app/dansmith/supplychainsim" width = "800" height = "600"></iframe>

Hosting an Interface Builder Simulation on Your Server

Alternately, you can host all the web files on your server directly. The benefits of this approach are:

  • You will have control of all the files for your simulation
  • You may have content you wish to keep internal to your organization, e.g. within a corporate firewall

Important notes

  • You will need to modify your simulation to make it send web service calls to Forio epicenter
  • The model for the simulation will still be hosted by Forio Epicenter,
  • Your simulation (hosted on your server) will still make web service calls to Forio Epicenter (hosted at api.forio.com).
  • If you change your simulation web files with Forio Epicenter, you will have to recopy the files to your server.

Here are the steps:

(1) Change relative src references to point to forio.com.

Interface builder references a number of scripts and CSS files that are hosted on forio.com. You will need to edit “index.html” to point to the Forio server.

Specifically, change any script tag that starts with a slash to have “https://forio.com” before it.

For example, in index.html, look for lines like this (there may be others)

<script src="/tools/js-libs/2.11.0/epicenter.min.js"></script>
<script src="/tools/js-libs/flow/1.0.1/flow.min.js"></script>
<link id="f-theme" rel="stylesheet" href="/epicenter/builder/project-files-v1/styles/bold.min.css">

and change them to a form like this. (do not copy the specific lines below, instead insert https://forio.com before the slash in the lines from your file).

<script src="https://forio.com/tools/js-libs/2.11.0/epicenter.min.js"></script>
<script src="https://forio.com/tools/js-libs/flow/1.0.1/flow.min.js"></script>
<link id="f-theme" rel="stylesheet" href="https://forio.com/epicenter/builder/project-files-v1/styles/bold.min.css">

(2) Tell the interface builder to use api.forio.com for all web service calls.

You can customize the hostname used for the Forio web service calls. In order to change this, look for a block of code in index.html that looks like this:

<script>
    //Flow.js will be auto-configured for this project, but you can use the code-block below to override or add any specific changes you want
    //See https://forio.com/epicenter/docs/public/data_binding_flow_js/#using_in_project for possible options
    window.FLOW_CONFIG = {
        channel: {
          
        }
    };
</script>

Replace that block with the following code. Change the variables accountName and projectName to be the account (short) name and project (short) name for your sim. Note that these should be lowercase (no space), and should be exact same names that appear in the sim URL.

<script>
var accountName = "dansmith";
var projectName = "supplychainsim";
window.FLOW_CONFIG = {
    channel: {
        defaults: {
            account: accountName,
            project: projectName,
            server: {
                host: 'api.forio.com',
            },
        },
        runManager: {
            run: {
                account: accountName,
                project: projectName,
                server: {
                    host: 'api.forio.com',
                }
            },
        }
    }
};
</script>

(3) Test the sim.

You should be able to see the sim run in the same manner as on Forio.com. There should be no new errors. You might it helpful to open up the “dev tools” in your browser and look at the network tab. Click “XHR” to see all web service calls and confirm they are going to “api.forio.com” and not to your server.

Questions or problems? Post a question in the forum and we’ll do our best to help!

1 Like

Many thanks for this. I tried “Embed the Simulation in an Iframe” and it works very well. The only thing I am still struggling with is how to make the iframe responsive to the size of the device that is being used. I searched on the internet and found some general approaches, but nothing that works specifically in my situation with Forio. It seems I need to set the height and width to 100% and then add an element, but I can not work out what this element should look like. Are you able to help on this? Regards, Tim.

Hi Tim,

It’s tricky. Iframes were designed to have fixed height and width. But this article gives a semi-complicated technique to do what you want.

Hi Tim,
If you’re supporting the latest versions of browsers (2019 and newer) then you can use CSS Flex

You can set the element that contains the iframe to “display: flex”, and set the height to 100%, width to 100%, and min-height to 100vh (assuming you want the iframe to take up the full height and width of the page)

Then style the iframe with width 100% and “flex-grow: 1” which will dynamically resize the iframe

Here is an example on jsfiddle
https://jsfiddle.net/hkumar1993/cwu7b540/7/

Thank you Will and Harsh. I am trying it out and will get back if there are any further questions.

Hi! I tried the method described above to be able to host a multiplayer project on our local server (which is on our local computer), but it did not work. Does it need to be hosted through https protocol, i.e. on the live server? Or there is different method for hosting multiplayer projects?

Thank you for beforehand your kind reply.

It sounds as though you are using a laptop to hold the HTML files on some kind of local web server, and accessing via other computers?

This is an unusual way of serving the sim. There’s a couple potential glitches.

  • One possible issue is that cookies will often not work without a domain name. E.g. if users are going to http://10.0.0.5/ the cookie may not be persisted. You’ll need to set up a domain name in your local DNS (e.g. sims.mylocal.com)
  • Another issue is that epicenter.js code works best with https. It shouldn’t be required, but it’s not robust when they are mixed. API calls to Forio must be https, but your local server is probably http. Look in dev tools to see if there’s calls failing due to the wrong protocol.
  • Finally, make sure the path matches. Sims are normally hosted at forio.com/app///files. Use the same path if you are hosting locally.

We recommend as a general rule you upload your files to forio.com to test there. You can use the freely available “forio-cli” tool ( https://github.com/forio/forio-cli ) to sync your local directory with the Forio hosted project.

1 Like