Compare commits
15 Commits
master
...
edc1ea081f
| Author | SHA1 | Date | |
|---|---|---|---|
| edc1ea081f | |||
| 87a3014c8d | |||
| 5e0768263f | |||
| 6bf0ca0d74 | |||
| 3bcb921032 | |||
| 963d4d1750 | |||
| afebaf0ee6 | |||
| 2d1eb509f1 | |||
| 0409c28e4c | |||
| 47680dff22 | |||
| 32a5491472 | |||
| 34ef078dfe | |||
| 28506fd3f0 | |||
| 85d5e342c1 | |||
| bfabca1845 |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
api2/
|
||||||
|
**/build/
|
||||||
|
out.js
|
||||||
|
api/node_modules/
|
||||||
34
Dockerfile
Normal file
34
Dockerfile
Normal 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
4
api/.haxerc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"version": "4.2.5",
|
||||||
|
"resolveLibs": "scoped"
|
||||||
|
}
|
||||||
9
api/build.hxml
Normal file
9
api/build.hxml
Normal 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
|
||||||
3
api/haxe_libraries/http-status.hxml
Normal file
3
api/haxe_libraries/http-status.hxml
Normal 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
|
||||||
7
api/haxe_libraries/hxnodejs.hxml
Normal file
7
api/haxe_libraries/hxnodejs.hxml
Normal 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()
|
||||||
4
api/haxe_libraries/tink_anon.hxml
Normal file
4
api/haxe_libraries/tink_anon.hxml
Normal 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
|
||||||
7
api/haxe_libraries/tink_await.hxml
Normal file
7
api/haxe_libraries/tink_await.hxml
Normal 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()
|
||||||
3
api/haxe_libraries/tink_chunk.hxml
Normal file
3
api/haxe_libraries/tink_chunk.hxml
Normal 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
|
||||||
3
api/haxe_libraries/tink_core.hxml
Normal file
3
api/haxe_libraries/tink_core.hxml
Normal 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
|
||||||
7
api/haxe_libraries/tink_http.hxml
Normal file
7
api/haxe_libraries/tink_http.hxml
Normal 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
|
||||||
5
api/haxe_libraries/tink_io.hxml
Normal file
5
api/haxe_libraries/tink_io.hxml
Normal 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
|
||||||
4
api/haxe_libraries/tink_json.hxml
Normal file
4
api/haxe_libraries/tink_json.hxml
Normal 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
|
||||||
4
api/haxe_libraries/tink_macro.hxml
Normal file
4
api/haxe_libraries/tink_macro.hxml
Normal 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
|
||||||
3
api/haxe_libraries/tink_priority.hxml
Normal file
3
api/haxe_libraries/tink_priority.hxml
Normal 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
|
||||||
5
api/haxe_libraries/tink_querystring.hxml
Normal file
5
api/haxe_libraries/tink_querystring.hxml
Normal 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
|
||||||
3
api/haxe_libraries/tink_spatial.hxml
Normal file
3
api/haxe_libraries/tink_spatial.hxml
Normal 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
|
||||||
7
api/haxe_libraries/tink_sql.hxml
Normal file
7
api/haxe_libraries/tink_sql.hxml
Normal 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
|
||||||
6
api/haxe_libraries/tink_streams.hxml
Normal file
6
api/haxe_libraries/tink_streams.hxml
Normal 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
|
||||||
4
api/haxe_libraries/tink_stringly.hxml
Normal file
4
api/haxe_libraries/tink_stringly.hxml
Normal 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
|
||||||
6
api/haxe_libraries/tink_syntaxhub.hxml
Normal file
6
api/haxe_libraries/tink_syntaxhub.hxml
Normal 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()
|
||||||
4
api/haxe_libraries/tink_typecrawler.hxml
Normal file
4
api/haxe_libraries/tink_typecrawler.hxml
Normal 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
|
||||||
5
api/haxe_libraries/tink_url.hxml
Normal file
5
api/haxe_libraries/tink_url.hxml
Normal 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
|
||||||
6
api/haxe_libraries/tink_web.hxml
Normal file
6
api/haxe_libraries/tink_web.hxml
Normal 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
|
||||||
2081
api/package-lock.json
generated
Normal file
2081
api/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
api/package.json
Normal file
15
api/package.json
Normal 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
0
api/readme.md
Normal file
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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
4945
api/res/txt/first-names.txt
Normal file
4945
api/res/txt/first-names.txt
Normal file
File diff suppressed because it is too large
Load Diff
88799
api/res/txt/last-names.txt
Normal file
88799
api/res/txt/last-names.txt
Normal file
File diff suppressed because it is too large
Load Diff
84
api/src/Server.hx
Normal file
84
api/src/Server.hx
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import html.WebDocument;
|
||||||
|
import tink.http.containers.*;
|
||||||
|
import tink.http.Response;
|
||||||
|
import tink.web.routing.*;
|
||||||
|
import tink.sql.drivers.Sqlite;
|
||||||
|
import db.Db;
|
||||||
|
|
||||||
|
import model.MUser;
|
||||||
|
|
||||||
|
import controller.IDGen;
|
||||||
|
import controller.User;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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.MUser.create();
|
||||||
|
// @await var two = db.MUser.insertOne({
|
||||||
|
// id: cast null,
|
||||||
|
// name: 'Alice',
|
||||||
|
// email: 'alice@example.com',
|
||||||
|
// password: 'jew'
|
||||||
|
// });
|
||||||
|
// @await var three = db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) {
|
||||||
|
// trace(row.name);return "";
|
||||||
|
// });
|
||||||
|
// // trace(@await one);
|
||||||
|
// // trace(@await two);
|
||||||
|
// trace(@await three);
|
||||||
|
// return '$yeet';
|
||||||
|
// }
|
||||||
|
|
||||||
|
@:sub('/user')
|
||||||
|
@:produces('application/json')
|
||||||
|
public function user()
|
||||||
|
return new User();
|
||||||
|
|
||||||
|
@: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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:sub('/idgen')
|
||||||
|
@:produces('application/json')
|
||||||
|
public function idGen()
|
||||||
|
return new IDGen();
|
||||||
|
|
||||||
|
}
|
||||||
48
api/src/Utils.hx
Normal file
48
api/src/Utils.hx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
public static function getTXT(path:String):String
|
||||||
|
{
|
||||||
|
var strout:String = "";
|
||||||
|
if(FileSystem.exists(path)){
|
||||||
|
strout = File.getContent(path);
|
||||||
|
}
|
||||||
|
return strout;
|
||||||
|
}
|
||||||
|
public static function parseLines(str:String):Array<String>
|
||||||
|
{
|
||||||
|
var lineArray:Array<String> = [];
|
||||||
|
if(str.indexOf("\r") == -1)
|
||||||
|
lineArray = str.split("\n");
|
||||||
|
else if(str.indexOf("\n") == -1){
|
||||||
|
lineArray = str.split("\r");
|
||||||
|
}
|
||||||
|
else if(str.indexOf("\r\n") == -1){
|
||||||
|
lineArray = str.split("\n\r");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
lineArray = str.split("\r\n");
|
||||||
|
}
|
||||||
|
return lineArray;
|
||||||
|
}
|
||||||
|
}
|
||||||
0
api/src/VDom.hx
Normal file
0
api/src/VDom.hx
Normal file
67
api/src/controller/IDGen.hx
Normal file
67
api/src/controller/IDGen.hx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package controller;
|
||||||
|
|
||||||
|
import haxe.Json;
|
||||||
|
import Utils;
|
||||||
|
|
||||||
|
typedef T_IDInfo = {
|
||||||
|
var firstname:String;
|
||||||
|
var lastname:String;
|
||||||
|
var birthDay:String;
|
||||||
|
var email:String;
|
||||||
|
var password:String;
|
||||||
|
}
|
||||||
|
|
||||||
|
class IDGen{
|
||||||
|
public function new() {}
|
||||||
|
public static var path:String = "./res/txt/first-names.txt";
|
||||||
|
public static var path2:String = "./res/txt/last-names.txt";
|
||||||
|
|
||||||
|
public static function genID()
|
||||||
|
{
|
||||||
|
|
||||||
|
var firstnames = Utils.parseLines(Utils.getTXT(path));
|
||||||
|
var lastnames = Utils.parseLines(Utils.getTXT(path2));
|
||||||
|
|
||||||
|
var firstname:String = firstnames[ Math.floor(Math.random()*firstnames.length)].toLowerCase();
|
||||||
|
var lastname:String = lastnames[ Math.floor(Math.random()*lastnames.length)].toLowerCase();
|
||||||
|
|
||||||
|
var birthyear:Int = 2003-Math.floor(Math.random()*60);
|
||||||
|
var birthyear2dig:Int = birthyear - 1900;
|
||||||
|
|
||||||
|
while(birthyear2dig >100){
|
||||||
|
birthyear2dig -=100;
|
||||||
|
}
|
||||||
|
|
||||||
|
var id:T_IDInfo = {
|
||||||
|
firstname: firstname,
|
||||||
|
lastname: lastname,
|
||||||
|
birthDay: "01/01/"+birthyear,
|
||||||
|
email: firstname+lastname+(birthyear2dig)+"@gmail.com",
|
||||||
|
password: "4123jk54jhejkrtsdr"
|
||||||
|
};
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:get('/')
|
||||||
|
@:produces('application/json')
|
||||||
|
public function id(){
|
||||||
|
var json:String = Json.stringify(genID());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:get('/firstnames')
|
||||||
|
@:produces('text/plain')
|
||||||
|
public function listfirstnames(){
|
||||||
|
var json:String = Utils.getTXT(path);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:get('/lastnames')
|
||||||
|
@:produces('text/plain')
|
||||||
|
public function listlastnames(){
|
||||||
|
var json:String = Utils.getTXT(path2);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
60
api/src/controller/User.hx
Normal file
60
api/src/controller/User.hx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package controller;
|
||||||
|
|
||||||
|
import haxe.Json;
|
||||||
|
import Utils;
|
||||||
|
import db.Db;
|
||||||
|
import model.MUser;
|
||||||
|
|
||||||
|
|
||||||
|
class User{
|
||||||
|
public function new() {}
|
||||||
|
public static var driver = new tink.sql.drivers.Sqlite();
|
||||||
|
@await public static var db = new Db('db.sqlite', driver);
|
||||||
|
|
||||||
|
|
||||||
|
@:get('/')
|
||||||
|
@:produces('text/plain')
|
||||||
|
public function id(){
|
||||||
|
var json:String = "test";
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:get('/registerDummyUser')
|
||||||
|
@:produces('text/plain')
|
||||||
|
public function registerdummyuser(){
|
||||||
|
|
||||||
|
//@await var db = new Db('daba2', driver);
|
||||||
|
db.MUser.create().next(function(){
|
||||||
|
db.MUser.insertOne({
|
||||||
|
id: cast null,
|
||||||
|
name: 'Alice',
|
||||||
|
email: 'alice@example.com',
|
||||||
|
password: 'jew'
|
||||||
|
}).next(function(){
|
||||||
|
db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) {
|
||||||
|
trace(row.name);
|
||||||
|
// return "$row";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return "success";
|
||||||
|
// @await var three = ;
|
||||||
|
// trace(@await one);
|
||||||
|
// trace(@await two);
|
||||||
|
// trace(three);
|
||||||
|
//return '$yeet';
|
||||||
|
// var json:String = Json.stringify(three);
|
||||||
|
// @await return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:get('/fetchalice')
|
||||||
|
@:produces('application/json')
|
||||||
|
public function fetchalice(){
|
||||||
|
var driver = new tink.sql.drivers.Sqlite();
|
||||||
|
|
||||||
|
return db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) {
|
||||||
|
return row;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
10
api/src/db/Connection.hx
Normal file
10
api/src/db/Connection.hx
Normal 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
17
api/src/db/Db.hx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package db;
|
||||||
|
|
||||||
|
// import tink.sql.drivers.Sqlite;
|
||||||
|
//import tink.sql.Database;
|
||||||
|
import tink.sql.Types;
|
||||||
|
import model.MUser;
|
||||||
|
|
||||||
|
// import db.Models.User;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef Db = tink.sql.Database<Def>;
|
||||||
|
@:tables(MUser)
|
||||||
|
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
11
api/src/db/Models.hx
Normal 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>;
|
||||||
|
// }
|
||||||
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(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
api/src/html/WebDocument.hx
Normal file
24
api/src/html/WebDocument.hx
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
9
api/src/model/MService.hx
Normal file
9
api/src/model/MService.hx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import tink.sql.Types;
|
||||||
|
|
||||||
|
typedef MService = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MService>;
|
||||||
|
public var name:VarChar<50>;
|
||||||
|
public var description:VarChar<1024>;
|
||||||
|
}
|
||||||
10
api/src/model/MSubscription.hx
Normal file
10
api/src/model/MSubscription.hx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import tink.sql.Types;
|
||||||
|
|
||||||
|
|
||||||
|
typedef MSubscription = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MSubscription>;
|
||||||
|
public var subscriber:Id<MUser>;
|
||||||
|
public var service:Id<MService>;
|
||||||
|
}
|
||||||
11
api/src/model/MUser.hx
Normal file
11
api/src/model/MUser.hx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import tink.sql.Types;
|
||||||
|
import model.MService;
|
||||||
|
|
||||||
|
typedef MUser = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MUser>;
|
||||||
|
public var name:VarChar<50>;
|
||||||
|
public var email:VarChar<50>;
|
||||||
|
public var password:VarChar<50>;
|
||||||
|
}
|
||||||
9
api/src/model/cctweaked/HTurtle.hx
Normal file
9
api/src/model/cctweaked/HTurtle.hx
Normal 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>;
|
||||||
|
}
|
||||||
17
api/src/model/services/DrivebyCool.hx
Normal file
17
api/src/model/services/DrivebyCool.hx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package model.sites.drivebycool;
|
||||||
|
|
||||||
|
import tink.sql.Types;
|
||||||
|
import model.MSubscription;
|
||||||
|
|
||||||
|
typedef MProject = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MProject>;
|
||||||
|
public var name:VarChar<50>;
|
||||||
|
public var owner:Id<MUser>;
|
||||||
|
public var description:VarChar<1024>;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef MMembership = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MMembership>;
|
||||||
|
public var project:Id<MProject>;
|
||||||
|
public var user:Id<MUser>;
|
||||||
|
}
|
||||||
16
api/src/model/services/ProjectTracker.hx
Normal file
16
api/src/model/services/ProjectTracker.hx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package model.services;
|
||||||
|
|
||||||
|
import tink.sql.Types;
|
||||||
|
|
||||||
|
typedef MMembership = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MMembership>;
|
||||||
|
public var project:Id<MProject>;
|
||||||
|
public var user:Id<MUser>;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef MProject = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MProject>;
|
||||||
|
public var name:VarChar<50>;
|
||||||
|
public var owner:Id<MUser>;
|
||||||
|
public var members:Id<MMembership>;
|
||||||
|
}
|
||||||
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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user