-
Notifications
You must be signed in to change notification settings - Fork 0
Controllers
Every controller should be placed inside the controller directory and the filename should be parsedPath+"Controller" so for example the path /Dashboard/something would lead to a a file in the Controller directory with the name DashboardController.ts. In the file a class that extends Controller should be exported as default. The name of the class is irrelevant
Every url path is splitted in to chunks after the slashes (/). The first chunk (index 0) is to declare the controller, the second chunk (index 1) is to declare the action. The following chunks are used for the params after the following syntax key/value.
Example structure: controller/action/key/value
Example of real url example.com/video-streaming/delete-video/id/1 This url will be parsed as following Controller name: VideoStreamingController Action name: deleteVideo Params: {id: "1"}
import Controller from "@lib/Controller";
export default class Users extends Controller {}import Controller from "@lib/Controller";
export default class Users extends Controller {
@GET
index() {
// Index route for the controller
// Route for this example is Users/
}
@POST
createUser() {
// Called whenever the user enters the path users/create-user with a POST request
}
@GET
edit() {
// example of how to use res
this.res.send("Hello world");
}
}setTokenData takes two required arguments and two optional argument
name is the key for the token and will be used if the token should be retrieved. value is the value stored in the token assignmentMethod declares what will happen if a token already exists with the provided name. Three options are possible
- renew - Data will be merged with Object.assign(oldData, newData) and the expiration time will be updated to the provided expiration time
- append- Same as renew but the expiration time from the old token will be kept
- overwrite - Token will be overwritten with new data and expiration time.
expiration number of seconds until the token expires, will be session based if no value is provided