Skip to content

Fundamentals

Hugo Persson edited this page Nov 21, 2020 · 2 revisions

File structure

You have three primary folders:

  1. Public
  2. Resources
  3. Src

Public

All files that should be publicly available should be placed inside public. For example if you place a index.html file inside public folder then a user can reach that file with the path /index.html.

Resources

All private resources should be placed inside here. The reason why this folder exists is when you compile your code the references to this folder will still work and files do not need to be moved to build.

Src

All code should be placed inside the the src folder, this folder will later be compiled from TypeScript to JavaScript. This code can be run with

npm run dev

and it can be compiled with

npm build

Index.ts

This is the start of your application, in this file we intitiate the framework and configure some settings. We also expose methods for handling requests 404 request and index action (/ path.

Boilerplate

import "module-alias/register"; // Needed for node to handle path aliases used in the application
import Core from "@lib/Core"; // The core of the framework
import Initialize from "@lib/Initialize"; // The base class for Initializing the project

class Start extends Initialize {
    core: Core;
    constructor() {
        super();
        this.core = new Core(this);
    }
}
new Start();

Methods

preStart(){
    // Called before the server is started
}
postStart() {
    // Called after the server has been started
}

noPageFound() {
    // 404 handler
    this.res.send("404");
}
indexAction() {
    // Called whenever the user don't specify a controller, meaning they used the / path

}

Clone this wiki locally