Is there a way to upload simple static website files on Glitch using cURL or official node module?

Hi, I wanted to host a static website which is a generated reports from unit and integrated test during CI pipeline build. Currently I see no official documentation on how to upload static website using Glitch API via command line. Thank you in advance!

It actually works the way you would expect:

What I mean is execute a command from my CI pipeline like using cURL to upload the generated static HTML on Glitch server, not using Glitch UI and terminal. This would mean I need to use some Glitch API via command line.

1 Like

Ok, but I still don’t get the big picture as it seems it’s not a typical glitch project setup. Where is the build happening?

The static html files are generated after executing unit and instrumented test of a mobile app project after running a CI pipeline. The objective is to simply upload these files on Glitch in a form of RESTful API or whatever is currently available to make it publicly available as web page.

Maybe try reverse engineering it, all requests are authenticated with your user token. Use the devtools requests panel, it might help.

And yes, there is no official API. You need to reverse engineer it. Btw Glitch is perfectly ok with reverse engineering some of their endpoints if you don’t abuse it.

a glitch project acts as a git remote. you should be able to push to it. there’s a config item you can set in the project to make it check out the new content into the project filesystem when it receives a git push.

I also have a CLI for glitch if you need to do anything more than that

Is there a documentation for this?

Do you have example or related documentation to it? I don’t think I can use the git approach since the generated page is under a build directory which is never being added on commits in general practice. I was hoping we can upload files on a Glitch project via cURL and REST API.

There’s an old trick to push build folder to a separate branch github - How to push only specific folders from Master branch to gh-pages branch? - Stack Overflow

If you’re creating your own tool chain, why not experiment and then ask for questions? I don’t think there is any step by step documentation for your specific solution.

if you’re opposed to using git for this, then maybe this rsync wrapper would be the right thing

https://snail-cli.glitch.me/help/rsync.html

1 Like

Unfortunately not using GitHub as repo host and stated already that using git is not the right way on my setup. Also with regards to your second statement, it will be hard to do experimentation when you do not know where to begin with specially if there is no available/related resource such as simple documentation stating that what I am trying to accomplish is possible with this platform. You will waste a lot of time if you do that and it is not rewarding considering that this is just a very simple deployment of static HTML. What I am trying to do is actually pretty easy with other platforms I was just hoping it will be much more easier on this platform, only “IF” Glitch offer such service/API in the first place.

I don’t quite understand it since I see no sample and it seems it is not requiring any API tokens? I would like to try and install this npm package in local machine and try to upload files from local machine to my Glitch project so there must be token to restrict this access right?

No, you’ll need to reverse-engineer it yourself.

Original response

It seems like it is sending a POST request to “s3.amazonaws.com/production-assetsbucket-xxxxxxx” with:

headers: {
    Content-Type: "multipart/form-data; boundary=---------------------------xxxxx",
},
body: "xxxxxxxx"

The body is something like:

-----------------------------xxxxxxxxxxxxxx
Content-Disposition: form-data; name="key"

48690336-169b-48d5-87d9-06221c1a7992/thumbnails/potato-788382326.jpg
-----------------------------xxxxxxxxxxxxxx
Content-Disposition: form-data; name="Content-Type"

image/jpeg
-----------------------------xxxxxxxxxxxxxx
Content-Disposition: form-data; name="Cache-Control"

max-age=xxxx
-----------------------------xxxxxxxxxxxxxx
Content-Disposition: form-data; name="AWSAccessKeyId"

XXXXXXXXXX
-----------------------------xxxxxxxxxxxxxx
Content-Disposition: form-data; name="acl"

public-read
-----------------------------192390485329079718204231412762
Content-Disposition: form-data; name="policy"

<a jwt here I think>
-----------------------------192390485329079718204231412762
Content-Disposition: form-data; name="signature"

xxxxxxxxxxxxxx=
-----------------------------xxxxxxxxxxxxxx
Content-Disposition: form-data; name="file"; filename="blob"
Content-Type: <format>

<file data>

Edit: Or you could just not use Glitch’s API and directly upload a file to your project using the exec API endpoint (thanks @wh0 for discovering this):

await fetch(`https://api.glitch.com/projects/{PROJECT ID}/exec`, {
  method: 'POST',
  headers: {
    'Authorization': '{AUTH TOKEN}',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    command: "cd assets && wget https://{FILE URL}",
  }),
});

To get your auth token, run this in the browser console on the glitch website:

prompt("Your token secret is: ", JSON.parse(localStorage.getItem("cachedUser")).persistentToken)

To get the project id, run this:

async function r(e) {prompt("Project ID:", (await (await fetch("https://api.glitch.com/projects/"+e)).json()).id)}r(prompt("Project domain (without '.glitch.me')"));
1 Like

Hi there - officially, no, we do not have an official Glitch API.

2 Likes

This is what I am looking for! Unfortunately it is not working, I tried to do POST request with Postman and after checking the generated code for JavaScript Fetch I think I followed your sample request correctly but getting 403 error and HTML response. Are you referring to this snail-cli/src/index.js at 49a660425236d5317cb504c7f7a082d3e73e2244 · wh0/snail-cli · GitHub

		<div class="info">
			<h1>Well, that was unexpected.</h1>
			<p>
				We’re not quite sure why, but something went wrong connecting to this project!
			</p>
			<p>
				It might be a blip. You can check our <a href="https://status.glitch.com/">status page</a> to see if
				Glitch is having problems.
			</p>
			<div class="button-wrap">
				<a class="button" href="//glitch.me">Back to Glitch</a>

			</div>
		</div>

Image url sample: https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSAn9KHM7pqkAS050u0JxCoqM3iwmSN1IiwyDXZsB-nvA&s

1 Like

That’s weird, it worked for me (I’m using hoppscotch)
The error seems like a problem with the persistent token, are you sure you didn’t put “Bearer” or something in front of it?

.

btw the project id is public, there is no need to hide it. the thing you should always hide is your persistent token - keep it safe and DO NOT share it with anyone

Also you don’t need to add "cd assets && " in the command, it’s just an example and it will fail if you don’t have a folder called “assets”


Yes, I got the URL from there. That’s why I credited @wh0

1 Like

I check and found that the project id is incorrect. The return value from this script is not the correct project id.

async function r(e) {prompt("Project ID:", (await (await fetch("https://api.glitch.com/projects/"+e)).json()).id)}r(prompt("Project domain (without '.glitch.me')"));

It could be that e value is incorrect, I tried to do the below instead to get the right project id.

https://api.glitch.com/v1/projects/by/domain?domain=my-project-name

After that it works now on my end, however I am getting 500 internal error despite a successful operation with wget on the project when using Postman while it works and get 200 OK with hoppscotch.

Anyway thanks a lot to you and @wh0 for helping us! This feature makes Glitch more fun to play with, I hope it will became official and public.

1 Like

With Glitch’s new “webhooks” feature available in the preview, I hope we will be able to automate things in our projects without having to reverse-engineer how everything works and deal with instability.

2 Likes

no sample

there’s meant to be a sample right on that help page:

# Upload the contents of a directory
snail rsync -- -aP notes/ my-domain:notes

it seems it is not requiring any API tokens?

use one of these methods to sign in snail auth — Snail or set your “persistent token” in the G_PERSISTENT_TOKEN environment variable.

further interactive samples here, under the “Sign in” and “Add your name” sections:

2 Likes