Multisite with new domains on the fly

Hi! I have an SaaS platform based on WordPress Multisite, and Iā€™m wondering if Frontity would work for me. Basically, this is what I need:

I need my users to sign up and have a new website created on the fly. This website will initially have a subdomain of my main domain (eg. johndoe.myapp.com), but the users should have the option to use a custom domain also (eg. johndoe.com).

Can I achieve that with Frontity? While I still use my multisite WordPress install as the CMS?

In the docs Iā€™ve noticed that Frontity have a configuration file that handles multiple domainsā€¦ Is there a way to make this ā€œdomain addingā€ automatic?

Thanks so much for the help!

1 Like

Hi @ronaldoscottis, welcome to the community :slightly_smiling_face:

Yes, you can achieve that with Frontity, although you would need to take care of all the configuration of your server, of course.

You can modify your frontity.settings.js on the fly but you need to rebuild the project each time you add a new site or a new package with npx frontity build.


We thought about a package system to replace frontity.settings.js with your own implementation but Iā€™ve been thinking about it lately and we could just support an async function export in frontity.settings.js.

export default async () => {
  const settings = await fetchSettingsFromSomeAPIorDB();
  return settings;
}

I donā€™t see any reason not to do that instead of a more complex package system. We could also open the door for storing the settings in the PHP plugin.

import wpSettings from "@frontity/wp-settings";

export default async () => {
  const settings = await wpSettings({
    api: "https://mywp.com/wp-json"
  });
  return settings;
}

What do you think? What approach are you going to use to modify the frontity.settings.js file on the fly?

Thanks for the warm welcoming @luisherranz!

I do not have a lot of experience with Frontity or React, Iā€™m in the learning phase right now. But, if there was a solution to handle this new site adition without having to rebuild the project every time, it would be awesome!

If I understod it right, I should host the Frontity project on a static serverless host, so not having to ā€œtouchā€ this part of the code seens to be a better practice.

Fetching the websites lists from a external source, or from the Wordpress install using the API, would be a good solution. It would mimic the behaviour of the WP Multisite itself.

Specially as in this case the ā€œlist of sitesā€ part would have constant updates, it seens more correct for it to be a dinamic resource than for it to be a configuration file.

At least to solve this specific problem, building a new package to replace the frontity.settings.js sounds like to much trouble for a small problem with simpler solutions.

Iā€™m probably going to need a couple weeks before actually start building something with Frontity, but it is very good to know that it is possible.

That is unlikely to happen in the near future because the JavaScript files need to be transpiled and bundled together using Babel and Webpack.

I guess the workflow should be something like:

  • A new site is created.
  • Update frontity.settings.js file with the new site info.
  • Trigger a new npx frontity build.
1 Like

Wouldnā€™t that rebuild cause a downtime for every other site that is using the same frontity project?

Not if you use a proper hosting that does the building in parallel and only points to the new build after it is completed, like Heroku. All serverless services also work that way (Zeit Now, AWS Lambdas, Firebase, GC Functionsā€¦).

3 Likes

4 posts were split to a new topic: Having problems deploying a Frontity site to Vercel

Hi there !

I have similar requirements. but when I use your explained method to get data on the fly in frontity.settings.js. It does not work for me. Error : Cannot read property ā€˜mapā€™ of undefined.

It is still in development or you have added in frontity project??

We havenā€™t added any functionality yet, but PRs are welcomed :slightly_smiling_face: