Skip to content

Instantly share code, notes, and snippets.

@cambiata
Created December 16, 2014 19:25
Show Gist options
  • Save cambiata/d01724cde4b87be37fb4 to your computer and use it in GitHub Desktop.
Save cambiata/d01724cde4b87be37fb4 to your computer and use it in GitHub Desktop.
Basic setup fro clientside UFront-MVC application
/**
* Basic setup for Client side UFront application
* @author Jonas Nyström
*/
class Client
{
public static var app:ufront.app.UfrontApplication;
static public function main() {
init();
app.execute(new ufront.web.context.HttpContext( new ClientRequest(), new ClientResponse()));
}
static function init() {
if ( app==null ) {
var config:ufront.web.UfrontConfiguration = {
indexController: TestController,
basePath: '/',
}
app = new ufront.app.UfrontApplication(config);
}
}
}
class ClientRequest extends ufront.web.context.HttpRequest {
public function new() {}
override function get_uri() return js.Browser.window.location.pathname;
override function get_scriptDirectory() return null;
override function get_httpMethod() return 'GET';
override function get_clientHeaders() return new ufront.core.MultiValueMap<String>();
override function get_cookies() return new ufront.core.MultiValueMap<String>();
override function get_query() return new ufront.core.MultiValueMap<String>();
override function get_post() return new ufront.core.MultiValueMap<String>();
}
class ClientResponse extends ufront.web.context.HttpResponse {
public function new() super();
override function flush() {
js.Browser.document.getElementById('content').innerHTML = _buff.toString();
//item(_buff.toString());
}
}
class TestController extends ufront.web.Controller {
@:route( '/' ) public function index() return "<ul><li>Home</li><li><a href='/staff/John'>Staff: John</a></li><li><a href='/staff/Jane'>Staff: Jane</a></li><li><a href='/contact'>Contact</a></li><li><a href='/pages/a/b/c/d'>Pages/*</a></li><li><a href='/sub/a'>subcontroller /a</a></li><li><a href='/sub/x/y/z'>subcontroller /*</a></li></ul>";
@:route( '/home' ) public function home() return index();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment