-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathHelloWorld.hx
More file actions
57 lines (53 loc) · 1.64 KB
/
HelloWorld.hx
File metadata and controls
57 lines (53 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import ufront.MVC;
/**
This is an example of how to initiate and execute a Ufront app.
The process differs slightly between client and server.
**/
class HelloWorld {
static function main() {
#if server
// Initialise the app on the server and execute the request.
var ufApp = new UfrontApplication({
indexController: HelloWorldController,
defaultLayout: "layout.html"
});
#if (php || neko)
ufApp.executeRequest();
#elseif nodejs
ufApp.listen();
#end
#elseif client
// Initialise the app on the client and respond to "pushstate" requests as a single-page-app.
var clientApp = new ClientJsApplication({
indexController: HelloWorldController,
defaultLayout: "layout.html"
});
clientApp.listen();
#end
}
}
/**
This is a very basic controller, that responds to URL routes and returns a view.
See `www/views/` for the HTML views we are using, using the default `haxe.Template` templating engine.
**/
class HelloWorldController extends Controller {
@:route("/$name")
public function hello( ?name:String="World" ) {
ufTrace( 'Hey $name, did you know we can trace directly to the browser console?' );
return new ViewResult({ title:'Hello $name' });
}
@:route(GET,"/signup/newname/")
public function newNameForm() {
return new ViewResult({ title:"Custom name" });
}
@:route(POST,"/signup/newname/")
public function submitNewName( args:{name:String} ):ActionResult {
if ( args.name.length>0 ) {
ufLog('Custom name ${args.name} entered');
return new RedirectResult( '/${args.name}/' );
}
else {
return new ViewResult({ title:"Custom name", error: "Please include your name" }, "newNameForm");
}
}
}