iTranslated by AI
A Guide to Building Simple Web Services for Free
When you think about building web services like e-commerce sites or platforms like note, they obviously require large-scale programs and incur server costs. However, you can operate simple web services for free.
For example, an "Omikuji (fortune-telling) site" only needs to use JavaScript to generate random numbers and display results like "Great Blessing (Daikichi)" or "Curse (Kyo)." You can also create sites that calculate "how much more score you need to reach S-rank in a game" using only JavaScript.
Since GitHub Pages is free, you can host such simple sites at no cost. For more details, see the article below.
When a Backend is Required
For instance, an e-commerce site needs more than just processing user input on the fly; it requires a backend to save order details in a database so they can be reviewed later, and to send order confirmation emails even when the user isn't on the page.
However, you can build this for free as well, provided the amount of data to be stored is small. As I learned from a site called Quora, there is something called GAS (Google Apps Script). You can use triggers to perform processes even when the user isn't viewing the page, and (although it requires the user to log in to their Google account) you can also save user-specific data.
Specific instructions on how to build one are explained step-by-step on the site below.
The following article is also helpful.
However, there are a few points to note:
- DOM content, in other words
windowordocument, cannot be used (though you can still retrieve information entered into forms). - When saving user data, you use userProperties, but since you can only save strings, you must convert objects using JSON functions when saving or retrieving them, like this:
const userProperties = PropertiesService.getUserProperties();
// Save sessionData as a string
userProperties.setProperty("sessionData", JSON.stringify(sessionData));
// Retrieve and parse the string back into an object
const sessionData = JSON.parse(userProperties.getProperty("sessionData"));
- To obtain the user's local time:
You can get the user's timezone withCalendarApp.getDefaultCalendar().getTimeZone(). Furthermore, here is how to get the time from aDateobject:
const getLocalHour = (date) => {
// https://stackoverflow.com/a/74683660/3809427
const offset = Number(Intl.DateTimeFormat("ia", {
timeZoneName: "shortOffset",
// https://stackoverflow.com/a/24764307/3809427
timeZone: CalendarApp.getDefaultCalendar().getTimeZone()
})
.formatToParts()
.find((i) => i.type === "timeZoneName").value // => "GMT+/-hh:mm"
.slice(3));
return (date.getUTCHours() + offset + 24) % 24;
}
Below is a tool I created for Bluesky that automatically self-reposts your own posts at different times to promote them.
SkySpread - Promote with automated self-reposts!
Discussion