Debian Codegraph @

extra/haxelib_src/src/website/Server.hx

raw
1 package website;
2
3 import website.controller.*;
4 import ufront.mailer.*;
5 import ufront.MVC;
6 import sys.*;
7 import sys.db.*;
8 import sys.io.*;
9 import haxe.io.*;
10
11 import haxelib.server.*;
12 import haxelib.server.Paths.*;
13
14 class Server {
15 static var ufApp:UfrontApplication;
16
17 static function main() {
18 // this is a temporary fix from https://github.com/dpeek/haxe-markdown/pull/26
19 @:privateAccess markdown.BlockParser.TableSyntax.TABLE_PATTERN = new EReg('^(.+?:?\\|:?)+(.+)$', '');
20
21 ufApp = new UfrontApplication({
22 indexController: HomeController,
23 templatingEngines: [TemplatingEngines.erazor],
24 defaultLayout: "layout.html",
25 logFile: "logs/haxelib.log",
26 sessionImplementation: VoidSession,
27 authImplementation: NobodyAuthHandler,
28 contentDirectory: "../uf-content/",
29 requestMiddleware: [],
30 responseMiddleware: [],
31 });
32 ufApp.injector.map( String, "documentationPath" ).toValue( neko.Web.getCwd()+"documentation-files/" );
33 ufApp.injector.map( UFCacheConnectionSync ).toClass( DBCacheConnection );
34 ufApp.injector.map( UFCacheConnection ).toClass( DBCacheConnection );
35
36 // var cacheMiddleware = new RequestCacheMiddleware();
37 // ufApp.addRequestMiddleware( cacheMiddleware, true ).addResponseMiddleware( cacheMiddleware, true );
38
39 // If we're on neko, and using the module cache, next time jump straight to the main request.
40 #if (neko && !debug)
41 neko.Web.cacheModule(run);
42 #end
43
44 // Execute the main request.
45 run();
46 }
47
48 static function run() {
49 var wasUpload = handleHaxelibUpload();
50 if ( wasUpload==false ) {
51 SiteDb.init();
52
53 var cacheAPI = new ufront.cache.DBCache.DBCacheApi();
54 cacheAPI.setup();
55
56 ufApp.executeRequest();
57 SiteDb.cleanup();
58 }
59 }
60
61 static function handleHaxelibUpload():Bool {
62 var tmpFile = null;
63 var tmpFileName = null;
64 var tmpFilePath = null;
65 var sid = null;
66 var bytes = 0;
67 neko.Web.parseMultipart(function(p,fileName) {
68 if( p == "file" ) {
69 sid = Std.parseInt(fileName);
70 tmpFilePath = Path.join([TMP_DIR, tmpFileName = sid+".tmp"]);
71 FileSystem.createDirectory(Path.directory(tmpFilePath));
72 tmpFile = sys.io.File.write(tmpFilePath, true);
73 } else
74 throw p+" not accepted";
75 },function(data,pos,len) {
76 bytes += len;
77 tmpFile.writeFullBytes(data,pos,len);
78 });
79 if( tmpFile != null ) {
80 tmpFile.close();
81 FileStorage.instance
82 .importFile(tmpFilePath, Path.join([TMP_DIR_NAME, tmpFileName]), true);
83 neko.Lib.print("File #"+sid+" accepted : "+bytes+" bytes written");
84 return true;
85 }
86 return false;
87 }
88 }