reCT

The only ByteSpace Project big enough to have its
own Website

ReCT On Rails!

using ReCT as a Backend

Didnt have the time to make this look pretty yet but itll do for now hehe

Introduction

RoR is a Web Framework for ReCT written in GoLang, that allows you to use ReCT code together with HTML (similar to ASP.NETs Razor and Php).
To display Text on the Page you just need to Print or Write it out.

Heres an example:


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>#{ Print("a creative title"); }#</title>
    </head>
    

(You can use all of ReCT functionallity and Packages)

With this simple system you can make fairly complex Websites, for example this very Website has been written in RoR!

Getting Started

The actual coding Docs are down here

To get started with a new RoR project just download the template from the top of this Page. You can put your HTML files, RORHTML files and Favicon into the www Directory. Any static files like CSS, images, fonts, etc need to go into the www/static Directory to be found by the Browser.


.html Files will be treated like normal standard HTML, .rorhtml will be treated as the RoR HTML + ReCT combo and compiled and then cached before shown.

Pipes

In RoR i added the concept of Pipes! Its basically a simple routing system that I added in because i was fed up with having to write out the same boilerplate code in every Project.
To confugure your pipes simply edit your connections.pipes File! By default the File should already have one Pipe set up:


        pipe / to /index.html
        

It just pipes all Requests to / (the website root) over to /index.html
Here are a few more examples: (btw everything prefixed by # is a comment)


        pipe / to /index.html

        pipe * to /everything.html     # pipe EVERYTHING to /everything.html
        pipe ? to /error.html          # pipe to /error.html if no file or pipe found

        pipe /page to /somepage.html   # pipe /page to /somepage.html
        pipe /page/* to /page.rorhtml  # pipe everything starting with /page/ to /page.rorhtml
        

Since v1.3 Pipes can even be domain specific. If a domain doesnt have an entry, the default (no domain) will be used. If the domain doesnt have its own Error handler, the default one will be used.


	pipe / to /index.html
	pipe ? to /error.html

	domain my.other.domain
		pipe * to /otherdomain.rorhtml
	end domain
	

If the requested File was found RoR will NOT check the Pipes. If you want it to ALWAYS check the Pipes (even when the file exists) just add #pipe_existing_files=true to the start of your connections.pipes file.

Server Settings

There are a few Settings for RoR you should know.

First one is the commandline Argument --shut. RoR is pretty verbose and prints a lot of debug info, when running a Site on a Server you probably dont want that, and you can shut it off this way.


Second one is the Environment Variable PORT. You can set the Port RoR is hosting on by changing this Variable. (Default is 8080)


Third one is the Environment Variable SSLPORT. You can set the Port RoR is hosting the SSL / HTTPS version of your site on. (Default is 443) (Only works if SSL is enabled)


Fourth one is the Evironment Variable RCTC_PATH. If you want to use a custom version, dont want to globally install RCTC or use RoR in a Docker Container you can set this Var to the Path of the RCTC executable.


Fifth one is the Environment Variable PLZ_HOST (yes thats really what i called it). If the www/static Directory isnt enough for you, you can just host more Directories using this Var. Just put in the <Directory to host>:<url to host at>

PLZ_HOST=www/someDir:/somedir/

This also supports multiple Directories seperated by semicolons.

PLZ_HOST="www/someDir:/somedir/;www/someOtherDir:/someotherdir/"

Sixth one is the commandline Argument --useSSL. This will turn on SSL / HTTPS. (put your server.key and server.crt into /ssl)
Last one is the commandline Argument --noCache. This will turn off any sort of caching (do NOT use this on a production site! This slows down operation a lot!).

Getting The Basic Data

To get the Requests URL you can simply use the url Variable. To get the Request-Type you can use the mode Variable which stores the Type as a string.
Heres an example Page using those Variables:


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>example page</title>
    </head>
    <body>
        <h1>Welcome!</h1>
        <p>You have connected to this site using the URL: #{ Print(url); }# on the Domain #{ Print(domain); }#
		using a '#{ Print(mode); }#' Request!</p>
    </body>
        

Form Fields

RoR lets you use HTML Forms to input data. (That includes URL-Encoded values from GET requests as well)

There are 2 main Functions for doing this, FieldExists(name string) and GetField(name string). The first one will return a Boolean and the second one will return the Fields value as a string.

The following example will have an HTML Form that sends Data to itself as a Post request, then it just outputs the Value.


    #{
        if (mode = "POST" && FieldExists("text")) // if we get a POST we can assume its from the Form
        {
            Print("You entered: " + GetField("text"));
            Stop();  //stops all output
        }
    }#
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>example page</title>
    </head>
    <body>
        <h1>Please enter any Text!</h1>
        <form method="POST">
            <input type="text" name="text">
        </form>
    </body>
        

File Uploads

RoR also allows you to upload Files using an HTML Form. The main Functions for this Task are UploadExists(name string) bool and GetUpload(name string) string. GetUpload will return a Path to where the File is temporarely stored.

File uploads are stored in the /cache/uploads directory and are deleted as soon as the Request finished processing, meaning that you will need to copy the File to save it.
(this can easely be done by using io::CopyFile(string, string))

Heres an Example that lets the User upload a File and then stores it in ./Upload:


    #{
        if (mode = "POST" && UploadExists("file")) // if we get a POST we can assume its from the Form
        {
            io::CopyFile(GetUpload("file"), "./Upload/");
            Print("File received!");
            Stop();  //stops all output
        }
    }#
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>example page</title>
    </head>
    <body>
        <h1>Please choose a File!</h1>
        <form method="POST">
            <input type="file" name="file">
        </form>
    </body>
        

Cookies

Yeah RoR also supports everyones favourite online Snack (funi). The main Functions here are CookieExists(name string) bool, GetCookie(name string) string and SetCookie(name string, value string, exprireInSeconds int)

The follwoing Example will use a Cookie to keep track of how many times the user has visited the Site.


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>example page</title>
    </head>
    <body>
        <h1>
        #{
            if (!CookieExists("timesvisited"))
                Print("Seems like youre Visiting for the first time!");
            else
                Print("You have visited this Site " + GetCookie("timesvisited") + " times!");

            //if cookie exists use its value if not use 0
            var numberOfVisits <- CookieExists("timesvisited") ? int(GetCookie("timesvisited")) : 0;
            numberOfVisits++;
            SetCookie("timesvisited", string(numberOfVisits), 9999);
        }#
        </h1>
    </body>
        

Small Extras

RoR has a function called Escape(html string) string which just turns all < and > into &lt; and &gt;


        #{
            Print(Escape("<script> alert('this wont cause any issues!') <script>"));
        }#