Compare commits

...

11 Commits

Author SHA1 Message Date
3bcb921032 dockerino 2022-09-12 12:11:37 +02:00
963d4d1750 updated libs 2022-09-09 12:40:38 +02:00
afebaf0ee6 added readme 2022-06-04 09:27:56 +02:00
2d1eb509f1 various changes 2022-06-04 09:27:49 +02:00
0409c28e4c updated build config 2022-06-04 09:27:39 +02:00
47680dff22 updated gitignore 2022-06-04 09:27:23 +02:00
32a5491472 added lix haxerc 2022-06-04 09:26:59 +02:00
34ef078dfe added lix libraries 2022-06-04 09:26:40 +02:00
28506fd3f0 renamed Document 2022-06-04 09:15:41 +02:00
85d5e342c1 Added current project files 2021-05-19 10:40:28 +02:00
bfabca1845 Added gitignore 2021-05-19 10:39:29 +02:00
43 changed files with 470 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
api2/
**/build/
out.js

34
Dockerfile Normal file
View File

@@ -0,0 +1,34 @@
FROM node:latest AS Build
RUN npm install haxe --global
RUN npm install lix --global --force
COPY ./api /app
WORKDIR /app
RUN lix scope
RUN lix download
RUN lix use haxe stable
# RUN lix install haxelib:hxnodejs
RUN haxe build.hxml
FROM node:latest
COPY --from=Build /app/build /app
COPY --from=Build /app/package.json /app/package.json
COPY --from=Build /app/res /app/res
WORKDIR /app/
RUN npm install
EXPOSE 8080
# CMD ["node", "out.js"]
CMD ["node", "out.js"]
# CMD ["/bin/bash"]

4
api/.haxerc Normal file
View File

@@ -0,0 +1,4 @@
{
"version": "4.2.5",
"resolveLibs": "scoped"
}

9
api/build.hxml Normal file
View File

@@ -0,0 +1,9 @@
-lib tink_http
-lib tink_web
#-lib tink_hxx
-lib tink_json
-lib tink_sql
-lib hxnodejs
-cp src
--main Server
-js build/out.js

View File

@@ -0,0 +1,3 @@
# @install: lix --silent download "haxelib:/http-status#1.3.1" into http-status/1.3.1/haxelib
-cp ${HAXE_LIBCACHE}/http-status/1.3.1/haxelib/src
-D http-status=1.3.1

View File

@@ -0,0 +1,7 @@
# @install: lix --silent download "haxelib:/hxnodejs#12.1.0" into hxnodejs/12.1.0/haxelib
-cp ${HAXE_LIBCACHE}/hxnodejs/12.1.0/haxelib/src
-D hxnodejs=12.1.0
--macro allowPackage('sys')
# should behave like other target defines and not be defined in macro context
--macro define('nodejs')
--macro _internal.SuppressDeprecated.run()

View File

@@ -0,0 +1,4 @@
# @install: lix --silent download "haxelib:/tink_anon#0.7.0" into tink_anon/0.7.0/haxelib
-lib tink_macro
-cp ${HAXE_LIBCACHE}/tink_anon/0.7.0/haxelib/src
-D tink_anon=0.7.0

View File

@@ -0,0 +1,7 @@
# @install: lix --silent download "haxelib:/tink_await#0.6.0" into tink_await/0.6.0/haxelib
-lib tink_core
-lib tink_macro
-lib tink_syntaxhub
-cp ${HAXE_LIBCACHE}/tink_await/0.6.0/haxelib/src
-D tink_await=0.6.0
--macro tink.await.Await.use()

View File

@@ -0,0 +1,3 @@
# @install: lix --silent download "haxelib:/tink_chunk#0.4.0" into tink_chunk/0.4.0/haxelib
-cp ${HAXE_LIBCACHE}/tink_chunk/0.4.0/haxelib/src
-D tink_chunk=0.4.0

View File

@@ -0,0 +1,3 @@
# @install: lix --silent download "gh://github.com/haxetink/tink_core#8fb0b9aa4de933614b5a04cc88da871b89cb8c6a" into tink_core/2.0.2/github/8fb0b9aa4de933614b5a04cc88da871b89cb8c6a
-cp ${HAXE_LIBCACHE}/tink_core/2.0.2/github/8fb0b9aa4de933614b5a04cc88da871b89cb8c6a/src
-D tink_core=2.0.2

View File

@@ -0,0 +1,7 @@
# @install: lix --silent download "haxelib:/tink_http#0.10.0" into tink_http/0.10.0/haxelib
-lib http-status
-lib tink_anon
-lib tink_io
-lib tink_url
-cp ${HAXE_LIBCACHE}/tink_http/0.10.0/haxelib/src
-D tink_http=0.10.0

View File

@@ -0,0 +1,5 @@
# @install: lix --silent download "haxelib:/tink_io#0.9.0" into tink_io/0.9.0/haxelib
-lib tink_chunk
-lib tink_streams
-cp ${HAXE_LIBCACHE}/tink_io/0.9.0/haxelib/src
-D tink_io=0.9.0

View File

@@ -0,0 +1,4 @@
# @install: lix --silent download "haxelib:/tink_json#0.11.0" into tink_json/0.11.0/haxelib
-lib tink_typecrawler
-cp ${HAXE_LIBCACHE}/tink_json/0.11.0/haxelib/src
-D tink_json=0.11.0

View File

@@ -0,0 +1,4 @@
# @install: lix --silent download "gh://github.com/haxetink/tink_macro#f3ddaa6496e3d0e82696c3ac9a7ccefac16954d4" into tink_macro/0.21.1/github/f3ddaa6496e3d0e82696c3ac9a7ccefac16954d4
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_macro/0.21.1/github/f3ddaa6496e3d0e82696c3ac9a7ccefac16954d4/src
-D tink_macro=0.21.1

View File

@@ -0,0 +1,3 @@
# @install: lix --silent download "haxelib:/tink_priority#0.1.4" into tink_priority/0.1.4/haxelib
-cp ${HAXE_LIBCACHE}/tink_priority/0.1.4/haxelib/src
-D tink_priority=0.1.4

View File

@@ -0,0 +1,5 @@
# @install: lix --silent download "haxelib:/tink_querystring#0.7.0" into tink_querystring/0.7.0/haxelib
-lib tink_typecrawler
-lib tink_url
-cp ${HAXE_LIBCACHE}/tink_querystring/0.7.0/haxelib/src
-D tink_querystring=0.7.0

View File

@@ -0,0 +1,3 @@
# @install: lix --silent download "gh://github.com/haxetink/tink_spatial#fb0d0a02ceed49325709215b5da0062fd8316c62" into tink_spatial/0.1.0/github/fb0d0a02ceed49325709215b5da0062fd8316c62
-cp ${HAXE_LIBCACHE}/tink_spatial/0.1.0/github/fb0d0a02ceed49325709215b5da0062fd8316c62/src
-D tink_spatial=0.1.0

View File

@@ -0,0 +1,7 @@
# @install: lix --silent download "gh://github.com/haxetink/tink_sql#9470dc0bd5557449992fbbfb15b3621e00c77e76" into tink_sql/0.0.0-alpha.0/github/9470dc0bd5557449992fbbfb15b3621e00c77e76
-lib tink_macro
-lib tink_spatial
-lib tink_streams
-lib tink_url
-cp ${HAXE_LIBCACHE}/tink_sql/0.0.0-alpha.0/github/9470dc0bd5557449992fbbfb15b3621e00c77e76/src
-D tink_sql=0.0.0-alpha.0

View File

@@ -0,0 +1,6 @@
# @install: lix --silent download "gh://github.com/haxetink/tink_streams#c51ff28d69ea844995696f10575d1a150ce47159" into tink_streams/0.3.3/github/c51ff28d69ea844995696f10575d1a150ce47159
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_streams/0.3.3/github/c51ff28d69ea844995696f10575d1a150ce47159/src
-D tink_streams=0.3.3
# temp for development, delete this file when pure branch merged
-D pure

View File

@@ -0,0 +1,4 @@
# @install: lix --silent download "haxelib:/tink_stringly#0.4.0" into tink_stringly/0.4.0/haxelib
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_stringly/0.4.0/haxelib/src
-D tink_stringly=0.4.0

View File

@@ -0,0 +1,6 @@
# @install: lix --silent download "haxelib:/tink_syntaxhub#0.5.0" into tink_syntaxhub/0.5.0/haxelib
-lib tink_macro
-lib tink_priority
-cp ${HAXE_LIBCACHE}/tink_syntaxhub/0.5.0/haxelib/src
-D tink_syntaxhub=0.5.0
--macro tink.SyntaxHub.use()

View File

@@ -0,0 +1,4 @@
# @install: lix --silent download "haxelib:/tink_typecrawler#0.7.0" into tink_typecrawler/0.7.0/haxelib
-lib tink_macro
-cp ${HAXE_LIBCACHE}/tink_typecrawler/0.7.0/haxelib/src
-D tink_typecrawler=0.7.0

View File

@@ -0,0 +1,5 @@
# @install: lix --silent download https://github.com/haxetink/tink_url/archive/7c98a2ea212c3a2f8d9ff41c1450eae98eee812f.tar.gz into tink_url/0.3.1/github/7c98a2ea212c3a2f8d9ff41c1450eae98eee812f
-D tink_url=0.3.1
-cp ${HAXESHIM_LIBCACHE}/tink_url/0.3.1/github/7c98a2ea212c3a2f8d9ff41c1450eae98eee812f/src
-lib tink_stringly

View File

@@ -0,0 +1,6 @@
# @install: lix --silent download "haxelib:/tink_web#0.3.0" into tink_web/0.3.0/haxelib
-lib tink_http
-lib tink_json
-lib tink_querystring
-cp ${HAXE_LIBCACHE}/tink_web/0.3.0/haxelib/src
-D tink_web=0.3.0

15
api/package.json Normal file
View File

@@ -0,0 +1,15 @@
{
"name": "drivebyapi",
"version": "1.0.0",
"description": "api",
"main": "out.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mysql": "^2.18.1",
"sqlite3": "^5.0.11"
}
}

0
api/readme.md Normal file
View File

0
api/res/html/index.html Normal file
View File

0
api/res/html/index.js Normal file
View File

View 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"
}
]
}

104
api/src/Server.hx Normal file
View File

@@ -0,0 +1,104 @@
import html.WebDocument;
import tink.http.containers.*;
import tink.http.Response;
import tink.web.routing.*;
import haxe.Json;
import tink.sql.drivers.Sqlite;
import db.Db;
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 "yeet";
return WebDocument.render();
}
@:get('/test')
@:produces('text/html')
@async
public function create(){
//return "yeet";
var yeet = "yote";
var driver = new tink.sql.drivers.Sqlite();
@await var db = new Db('daba2', driver);
@await var one = db.User.create();
@await var two = db.User.insertOne({
id: cast null,
name: 'Alice',
email: 'alice@example.com',
password: 'jew'
});
@await var three = db.User.select({name: User.name, email: User.email}).where(User.email == 'alice@example.com').first().next(function(row) {
trace(row.name);return "";
});
// trace(@await one);
// trace(@await two);
trace(@await three);
return '$yeet';
}
@:sub('/projects')
@:produces('application/json')
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
View 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
View File

10
api/src/db/Connection.hx Normal file
View File

@@ -0,0 +1,10 @@
package db;
import tink.sql.drivers.sys.Sqlite;
import tink.sql.drivers.MySql;
import db.Db;
class Connection{
private static var driver = new tink.sql.drivers.Sqlite();
public static var db = new Db('daba', driver);
}

17
api/src/db/Db.hx Normal file
View File

@@ -0,0 +1,17 @@
package db;
// import tink.sql.drivers.Sqlite;
//import tink.sql.Database;
import tink.sql.Types;
import model.User;
// import db.Models.User;
typedef Db = tink.sql.Database<Def>;
@:tables(User)
interface Def extends tink.sql.DatabaseDefinition {
//@:procedure var func:Int->{x:Int, point:tink.s2d.Point};
//@:table('user') var UserAlias:User;
}

11
api/src/db/Models.hx Normal file
View File

@@ -0,0 +1,11 @@
package db;
import tink.sql.Types;
typedef User = {
@:autoIncrement @:primary public var id(default, null):Id<User>;
var name:VarChar<255>;
@:unique var email:VarChar<255>;
var password:VarChar<255>;
}

View File

@@ -0,0 +1,8 @@
package html;
class BaseRenderable{
public var bIsContainer:Bool = true;
public function render(){
}
}

View File

@@ -0,0 +1,7 @@
package html;
class RenderableContainer extends BaseRenderable{
override function render() {
super.render();
}
}

44
api/src/html/Tag.hx Normal file
View 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;
}
}

View File

@@ -0,0 +1,24 @@
package html;
//import tink.web.macros.Routing;
import tink.web.routing.*;
import tink.web.routing.Router;
class WebDocument{
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();
}
}

11
api/src/model/User.hx Normal file
View File

@@ -0,0 +1,11 @@
package model;
import tink.sql.Types;
typedef User = {
@:autoIncrement @:primary public var id(default, null):Id<User>;
public var name:VarChar<50>;
public var email:VarChar<50>;
public var password:VarChar<50>;
}

View File

@@ -0,0 +1,9 @@
package model.cctweaked;
import tink.sql.Types;
typedef HTurtle = {
@:autoIncrement @:primary public var id(default, null):Id<HTurtle>;
public var name:VarChar<50>;
public var password:VarChar<50>;
}

0
api/src/res/a Normal file
View File

View 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"
}
]
}