changes, ok?
This commit is contained in:
+42
-8
@@ -4,27 +4,35 @@ import tink.http.Response;
|
||||
import tink.web.routing.*;
|
||||
import tink.sql.drivers.Sqlite;
|
||||
import db.Db;
|
||||
import haxe.Json;
|
||||
|
||||
import model.MUser;
|
||||
|
||||
import controller.IDGen;
|
||||
import controller.User;
|
||||
|
||||
import db.Db.Database as Db;
|
||||
|
||||
|
||||
typedef T_project = {
|
||||
name : String,
|
||||
description : String,
|
||||
url : String
|
||||
}
|
||||
typedef T_projects = {
|
||||
version : Int,
|
||||
projects : Array<T_project>
|
||||
}
|
||||
|
||||
class Server {
|
||||
@await public static var db:Db;
|
||||
static function main() {
|
||||
var container = new NodeContainer(8080);
|
||||
//var container = PhpContainer.inst; //use PhpContainer instead of NodeContainer when targeting PHP
|
||||
var router = new Router<Root>(new Root());
|
||||
Db.createTables();
|
||||
container.run(function(req) {
|
||||
return router.route(Context.ofRequest(req))
|
||||
.recover(OutgoingResponse.reportError);
|
||||
});
|
||||
}
|
||||
public static var db:
|
||||
}
|
||||
|
||||
class Root {
|
||||
@@ -65,10 +73,10 @@ class Root {
|
||||
public function user()
|
||||
return new User();
|
||||
|
||||
// @:sub('/projects')
|
||||
// @:produces('application/json')
|
||||
// public function projects()
|
||||
// return new Projects();
|
||||
@:sub('/projects')
|
||||
@:produces('application/json')
|
||||
public function projects()
|
||||
return new Projects();
|
||||
|
||||
@:get('/hello')
|
||||
@:produces('application/json')
|
||||
@@ -84,3 +92,29 @@ class Root {
|
||||
return new IDGen();
|
||||
|
||||
}
|
||||
|
||||
class Projects {
|
||||
public function new() {}
|
||||
|
||||
public var path:String = "./res/json/projects.json";
|
||||
|
||||
@:get('/')
|
||||
@:produces('application/json')
|
||||
public function projects(){
|
||||
var json:String = Utils.getJson(path);
|
||||
return json;
|
||||
}
|
||||
@:get('/project/by_name/$name')
|
||||
@:produces('application/json')
|
||||
public function project(name:String){
|
||||
var json:String = Utils.getJson(path);
|
||||
var _projects:T_projects = Json.parse(json);
|
||||
json = "{}";
|
||||
for(_project in _projects.projects){
|
||||
if(_project.name == name){
|
||||
json = tink.Json.stringify(_project);
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user