-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Suggestion] Use url shortener for playground urls #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm happy to have playground hit an API with the right params, but we can't host a shortener ourselves 👍 We can add a "how long do you want this link to live" option (with a max of say 6 months) then the biggest question is how to store it. It's probably just a key value store with the key being the URL path and an expiration date attached. I know that @robertwestbury has explored one for the TypeScript community discord, so maybe you can work with them on that? |
Recently I worked a lot with Firebase Cloud functions which would be probably better than a single Node processing handling all requests. I have no experience with scaling Node. Also unsure what DB would be used there. Firebase has pretty high free limits. 1 million reads (= requests) per month (50K per day) and a whole bunch of writes (see calculator). Even scheduled functions that can run a cleanup once in a while. I am not sure if there are some numbers of how many people use the Playground, but sounds sustainable to me. Eventually, it might require some small amounts of money, but hopefully, the community would be willing to donate a few bucks for that. Or perhaps Microsoft has some budget to make that possible? Google might be willing to provide some cheaper Firebase plan for the OSS project. The "hardest" step right now is to pick and register some nice domain. I was thinking about something like |
I would vote against play.ts (think about deno) Why not ts.play? |
I am not aware there would be such TLD as Alternatively, I am thinking we might not need a full custom domain. We could utilize Zeit Now and basically get a domain like I guess I will dive right into it and create some initial POC, it shouldn't be that hard really. |
I also not deep into domain registrations. |
Alright, an initial version is up & running 🎉 Repo: https://github.com/FredyC/ts-play-shortener Here is the example request to register a new playground to shorten. The Notice that with the same The produced shortened url is for example https://tsplay.now.sh/rhetorical-house-I2Nv It seems fast enough when there is traffic that keeps an underlying cloud function alive. Without traffic, it will go to sleep and it might take a few seconds to wake up. If this turns out to be an annoying problem, we can try to find a different serverless provider. That code is mostly not specific to Firebase. @orta Let me know what you think. Is API like that ok to you? I did not bother with expiration just yet, we can expand that later. |
I've switch it to
This API feels good, yeah, I'd maybe look into making the tsplay.now.sh pass through the API POST (so instead your API address is something like but yep, that works for me 👍 (that code needs a license BTW) |
Thanks for the feedback. I will switch base URL for sure, did not know about those.
Surprise surprise, it actually works already :) Here is the proof. The whole "frontend" part is ultra-thin, it's basically just this "rewrites": [
{
"source": "/(.*)",
"destination": "https://europe-west1-ts-play-a4c7e.cloudfunctions.net/main/$1"
}
] And I have added a license. |
Alright, changed base url, so now I am expecting the Do you need some help integrating it into the playground? I wasn't even able to find source code, so I would some pointers in that case. |
@orta Can I help to integrate this into a playground? Had a couple of situation where I could really use it and I opted for doing it manually. Can you point me out to the code so I can start working on the PR? |
Sure you can. The source code for the v3 exporter is here: https://github.com/microsoft/TypeScript-Website/blob/v2/packages/playground/src/exporter.ts And the definitions of the exports are here: https://github.com/microsoft/TypeScript-website/blob/81dabadf26a0cfc3c9635bfc8aa4caaa1d3056dd/packages/typescriptlang-org/src/templates/play.tsx#L192-L193 If you want to add it to the old playground, https://github.com/orta/typescript-play/ Maybe a new option in the dropdown which is "Create short link" ? |
Yea, I wouldn't bother with "old playground" as it's not covered by shortener anyway. Thanks for pointers, I will have a look at it soon. |
Btw, why is V3 in the branch called |
The site is v2, but we're on the third iteration on the playground 👍 |
There's a playground plugin for this: https://www.npmjs.com/package/typescript-playground-link-shortener |
Ah, I totally forgot about this and someone was faster with their own solution. Oh well, I learned stuff, so it was good effort :) Thanks for the heads up. |
Whenever I want to share some code eg. over the Slack, it fills almost the whole screen. It would be so great after hitting save to get shortened url in the clipboard.
I wonder what it takes to set up something custom (except some clever domain name). Given it could get polluted pretty fast, it should have some cleanup routines to remove old ones. I might be willing to take on this little project by myself, just could use some pointers and hints. And of course, some approval if it does even make sense to you.
The text was updated successfully, but these errors were encountered: