Compare commits
2 Commits
1fffc6103f
...
85d5e342c1
| Author | SHA1 | Date | |
|---|---|---|---|
| 85d5e342c1 | |||
| bfabca1845 |
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
./api/build/
|
||||||
|
out.js
|
||||||
8
api/build.hxml
Normal file
8
api/build.hxml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
-lib tink_http
|
||||||
|
-lib tink_web
|
||||||
|
-lib tink_hxx
|
||||||
|
-lib tink_json
|
||||||
|
-lib hxnodejs
|
||||||
|
-cp src
|
||||||
|
--main Server
|
||||||
|
-js build/out.js
|
||||||
0
api/res/html/index.html
Normal file
0
api/res/html/index.html
Normal file
0
api/res/html/index.js
Normal file
0
api/res/html/index.js
Normal file
20
api/res/json/projects.json
Normal file
20
api/res/json/projects.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
78
api/src/Server.hx
Normal file
78
api/src/Server.hx
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
api/src/Utils.hx
Normal file
24
api/src/Utils.hx
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
0
api/src/VDom.hx
Normal file
0
api/src/VDom.hx
Normal file
8
api/src/html/BaseRenderable.hx
Normal file
8
api/src/html/BaseRenderable.hx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package html;
|
||||||
|
|
||||||
|
class BaseRenderable{
|
||||||
|
public var bIsContainer:Bool = true;
|
||||||
|
public function render(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
18
api/src/html/Document.hx
Normal file
18
api/src/html/Document.hx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
7
api/src/html/RenderableContainer.hx
Normal file
7
api/src/html/RenderableContainer.hx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package html;
|
||||||
|
|
||||||
|
class RenderableContainer extends BaseRenderable{
|
||||||
|
override function render() {
|
||||||
|
super.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
44
api/src/html/Tag.hx
Normal file
44
api/src/html/Tag.hx
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
0
api/src/res/a
Normal file
0
api/src/res/a
Normal file
20
api/src/res/json/projects.json
Normal file
20
api/src/res/json/projects.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"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