Automatically generating of a new glitch website from another glitch website...is it possible?

Hi there!

I want to have a site that lets users fill out a form where they can add images, and when they press submit, a brand new glitch website is automatically generated that uses those images as assets in the code.

For example, if I want to create a website that generates custom online birthday cards for people, they would type in what they want to say in the card along with images to put in the online card, press submit, and then be sent an email with the link (a custom URL) their custom online card. This should all be automatic.

Is this possible with Glitch?

Thanks!
Ben

1 Like

Hmm I think so, but I’m away from my PC for a few days and I don’t think I can try.

A few problems with this is:
Whose account will the project belong to?

For every user that visits the site and makes a website will it have to make a new glitch account? (extremely bad idea)

Hi @scheerio This can absolutely be accomplished with a little url magic.

Here’s an outline of one approach:

  1. With this approach you’ll have two interrelated projects - the one that the user uses to set up the card and a project that’s remixed to actually create the card for the user.
  2. You’ll have to handle uploading the images to some location. Glitch doesn’t provide a documented API to upload images to a project’s assets drawer, but there are any number of places you can store an image for free; you just need to be able to retrieve the url where the image can be accessed after upload.
  3. Glitch allows you to pass values to a remix’s .env file (see https://remix-button.glitch.me/ for details). For the card message you’ll want to surround the message with double-quotes so that it sets your env variable as something that can actually be read as a unit. The image url can be passed as-is.
  4. on the card setup project’s submit you’ll email a link constructed to remix your remix target project with the appropriate values in the url to set the corresponding env variables. You’ll want to use a mailing service like SendGrid to send your emails.
  5. in the project to be remixed your start script should check to see if it is itself a remix (you can check the project id using process.env.PROJECT_ID and compare it to your remix project’s id which you can get from the browser’s console - if you open the console on the Editor’s page the project id will be logged there).
  6. if it’s a remix you’ll do whatever you need to do to create the card you want created using the values from the .env file
  7. When someone clicks on the link you provide they’ll be directed to the remixed project. If they’re logged in to Glitch it will be created under their Glitch account; if not it will be created for a new anonymous user and if they log in it will be merged with their existing projects.

There are undoubtedly other approaches that might be simpler, but this should serve as a starting point.

Please let us know how it goes. Happy Glitching!

1 Like

Can I feature request a documented api?

@King-Knight-Mare you’re welcome to add a topic to https://support.glitch.com/c/feature-ideas with a general or specific API request. A public API is on our roadmap, but it’s not likely to come in the near future.

1 Like

@cori, thank you SO much for this! I suspected that the .env approach would be good. Do you have any recommendations for how to handle getting uploaded images into new projects in a fully automated way? You touched on that, but I was wondering if you had any ideas. The part that is tricky to me is getting that image URL into the code. In your method described, I would assume the image URLs would go into the .env as well.

Yes, that’s right on, @scheerio, my thought was that you’d put the url to the image in .env and then reference it in your code to create the card. Once the image has an internet-accessible address you could use child_process.exec() to wget the image into your project. You could probably also use Node on the server to save the image to a subdirectory of your project’s home folder, but that won’t help you much in this pattern, because that file won’t be present in the project that’s going to need it (the remix target project) which is why I went the route of dropping the selected image on an image hosting platform.

C Web Build Beta will help you out! cwebbuildbeta.glitch.me

It is broken.


What?! I’ll investigate.

@RiversideRocks Thanks for alerting me! I’ll try to fix it.

it doesnt even work.

Screenshot_561

1 Like

The create button is broken. I’ll see what happened.

The main area is working, it’s the inside that’s broken. I’ll see what happened.
UPDATE: Our internal works. https://cwbbeta2.glitch.me/ loads.

2 Likes

I kinda created something similar in https://glitch.com/~birthday-card-generator, where a user inputs data, and uses the Glitch API to add the values as .env variables to the new project (.env values can be added/modified to a new project by passing arguments to the URL), which then generates a card based on those details.

1 Like