Last active
August 29, 2015 14:09
-
-
Save cambiata/be619dbf367b700f068c to your computer and use it in GitHub Desktop.
Ufront minimalistic server - No db, no sessions, no auth, just a simple server setup with basic controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app.controller; | |
import ufront.web.Controller; | |
import ufront.web.result.ContentResult; | |
class TestController extends 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(); | |
@:route( '/staff.html' ) public function staff() return "Staff"; | |
@:route( '/staff/$name/' ) public function viewStaff( name:String ) return 'Staff: $name'; | |
@:route( '/contact/', GET ) public function contact() return "Contact <form method='POST' action='/contact/'><p>Name:<br/><input name='name' /></p><p>Age:<br/><input name='age' /></p><input type='submit'/></form>"; | |
@:route( '/contact/', POST ) public function contactPost( args: { ?name:String, ?age:Int}) return 'Contact Post ' + Std.string(args); | |
@:route( '/content/*') public function testcontent(rest:Array<String>) return new ContentResult(Std.string(rest.join(', '))); | |
@:route( '/pages/*' ) public function pageCatchAll( rest:Array<String> ) return new ufront.web.result.ContentResult( Std.string(rest), "text/html" ); | |
@:route( '/sub/*' ) public var subController:SubController; | |
} | |
class SubController extends Controller { | |
@:route( '/a' ) function subA() return new ContentResult('This is /sub/a'); | |
@:route( '/b' ) function subB() return new ContentResult('This is /sub/b'); | |
@:route( '/*' ) function subElse() return new ContentResult('This is /sub/*'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Need to replace ufront.web.UfrontConfiguration line 221 "cast EasyAuth" with "null"! | |
-lib ufront | |
-cp src | |
-neko bin/index.n | |
-main Server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import ufront.app.UfrontApplication; | |
import ufront.web.UfrontConfiguration; | |
import app.controller.TestController; | |
class Server | |
{ | |
public static var app:UfrontApplication; | |
static public function main() { | |
init(); | |
app.executeRequest(); | |
} | |
static function init() { | |
if ( app==null ) { | |
var config:UfrontConfiguration = { | |
indexController: TestController, | |
//remotingApi: null, | |
//contentDirectory: null, | |
//urlRewrite: false, | |
basePath: '/', | |
} | |
app = new UfrontApplication(config); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment