Compare commits
No commits in common. "85d5e342c1020a3e225cd454f75f60c3660fd508" and "1fffc6103fa7113403be0b4d3487fb814d23f0fd" have entirely different histories.
85d5e342c1
...
1fffc6103f
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
|
|
||||||
./api/build/
|
|
||||||
out.js
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
-lib tink_http
|
|
||||||
-lib tink_web
|
|
||||||
-lib tink_hxx
|
|
||||||
-lib tink_json
|
|
||||||
-lib hxnodejs
|
|
||||||
-cp src
|
|
||||||
--main Server
|
|
||||||
-js build/out.js
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"version" : 1,
|
|
||||||
"projects" : [
|
|
||||||
{
|
|
||||||
"name": "subsonicsnl",
|
|
||||||
"description": "subsonics.nl website",
|
|
||||||
"url": "https://subsonics.nl"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "drivebycool",
|
|
||||||
"description": "driveby.cool website",
|
|
||||||
"url": "https://driveby.cool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "VaV Arena",
|
|
||||||
"description": "Q3 CPMA inspired arena shooter",
|
|
||||||
"url": "https://vav.driveby.cool"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,78 +0,0 @@
|
|||||||
import html.Document;
|
|
||||||
import tink.http.containers.*;
|
|
||||||
import tink.http.Response;
|
|
||||||
import tink.web.routing.*;
|
|
||||||
import haxe.Json;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef T_project = {
|
|
||||||
name : String,
|
|
||||||
description : String,
|
|
||||||
url : String
|
|
||||||
}
|
|
||||||
typedef T_projects = {
|
|
||||||
version : Int,
|
|
||||||
projects : Array<T_project>
|
|
||||||
}
|
|
||||||
|
|
||||||
class Server {
|
|
||||||
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());
|
|
||||||
container.run(function(req) {
|
|
||||||
return router.route(Context.ofRequest(req))
|
|
||||||
.recover(OutgoingResponse.reportError);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Root {
|
|
||||||
public function new() {}
|
|
||||||
|
|
||||||
|
|
||||||
@:get('/')
|
|
||||||
@:produces('text/html')
|
|
||||||
public function root(){
|
|
||||||
return Document.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
@:sub('/projects')
|
|
||||||
public function projects()
|
|
||||||
return new Projects();
|
|
||||||
|
|
||||||
@:get('/hello')
|
|
||||||
@:produces('application/json')
|
|
||||||
public function hello(name = 'world'){
|
|
||||||
var greeting = { hello: name, foo: 42 };
|
|
||||||
var strout:String = tink.Json.stringify(greeting);
|
|
||||||
return strout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
package;
|
|
||||||
|
|
||||||
import sys.io.File;
|
|
||||||
import sys.FileSystem;
|
|
||||||
|
|
||||||
|
|
||||||
class Utils{
|
|
||||||
public static function getHTML(path:String):String
|
|
||||||
{
|
|
||||||
var strout:String = "<html></html>";
|
|
||||||
if(FileSystem.exists(path)){
|
|
||||||
strout = File.getContent(path);
|
|
||||||
}
|
|
||||||
return strout;
|
|
||||||
}
|
|
||||||
public static function getJson(path:String):String
|
|
||||||
{
|
|
||||||
var strout:String = "{}";
|
|
||||||
if(FileSystem.exists(path)){
|
|
||||||
strout = File.getContent(path);
|
|
||||||
}
|
|
||||||
return strout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
package html;
|
|
||||||
|
|
||||||
class BaseRenderable{
|
|
||||||
public var bIsContainer:Bool = true;
|
|
||||||
public function render(){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
package html;
|
|
||||||
|
|
||||||
class Document{
|
|
||||||
public static function render():String
|
|
||||||
{
|
|
||||||
var docroot:Tag = new Tag("html");
|
|
||||||
var head:Tag = new Tag("head");
|
|
||||||
var body:Tag = new Tag("body");
|
|
||||||
var h1:Tag = new Tag("h1",['class="yeet"'],"Api endpoints:");
|
|
||||||
var a_yeet:Tag = new Tag("a",['href="projects"'],"projects");
|
|
||||||
var a_yeet:Tag = new Tag("a",['href="projects/project/by_name/"'],"projects");
|
|
||||||
docroot.children.push(head);
|
|
||||||
docroot.children.push(body);
|
|
||||||
body.children.push(h1);
|
|
||||||
body.children.push(a_yeet);
|
|
||||||
return docroot.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
package html;
|
|
||||||
|
|
||||||
class RenderableContainer extends BaseRenderable{
|
|
||||||
override function render() {
|
|
||||||
super.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
package html;
|
|
||||||
|
|
||||||
class Tag{
|
|
||||||
public var children:Array<Tag> = [];
|
|
||||||
public var name:String = "";
|
|
||||||
public var props:Array<String>;
|
|
||||||
public var textonly:Bool;
|
|
||||||
public var text:String = "";
|
|
||||||
public static var dochead:Tag;
|
|
||||||
public function new(_name:String, _props:Array<String>=null, _text = "", _textonly=false){
|
|
||||||
name = _name;
|
|
||||||
textonly = _textonly;
|
|
||||||
if(_props != null) props = _props;
|
|
||||||
text = _text;
|
|
||||||
}
|
|
||||||
public static function createTextElement(_text:String):Tag
|
|
||||||
{
|
|
||||||
var tag = new Tag("t",null,_text,true);
|
|
||||||
tag.text = _text;
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
public function render():String
|
|
||||||
{
|
|
||||||
var strout:String = "";
|
|
||||||
if(!textonly){
|
|
||||||
var strProps:String = "";
|
|
||||||
if(props != null){
|
|
||||||
for(prop in props) strProps+=prop+" ";
|
|
||||||
}
|
|
||||||
strout+="<"+name+" "+strProps+" "+">";
|
|
||||||
strout+=text;
|
|
||||||
trace(text);
|
|
||||||
for(tag in children){
|
|
||||||
strout+=tag.render();
|
|
||||||
}
|
|
||||||
strout+="</"+name+">";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
strout = text;
|
|
||||||
}
|
|
||||||
trace(strout);
|
|
||||||
return strout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"version" : 1,
|
|
||||||
"projects" : [
|
|
||||||
{
|
|
||||||
"name": "subsonicsnl",
|
|
||||||
"description": "subsonics.nl website",
|
|
||||||
"url": "https://subsonics.nl"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "drivebycool",
|
|
||||||
"description": "driveby.cool website",
|
|
||||||
"url": "https://driveby.cool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "VaV Arena",
|
|
||||||
"description": "Q3 CPMA inspired arena shooter",
|
|
||||||
"url": "https://vav.driveby.cool"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user