isundil 1 year ago
parent
commit
145e61a7bb
2 changed files with 48 additions and 6 deletions
  1. 42 0
      examples/main.js
  2. 6 6
      main.js

+ 42 - 0
examples/main.js

@@ -0,0 +1,42 @@
+#!/bin/node
+
+const CONFIG = require('craftlabhttpserver/src/config.js');
+CONFIG.Initialize(
+    {
+        port: { value: 80, valid: CONFIG.validNumber },
+        instanceHostname: { value: require('os').hostname(), valid: CONFIG.validNotEmptyString },
+        ldapUrl: { value: "", valid: CONFIG.validNotEmptyString },
+        ldapBindDN: { value: "", valid: CONFIG.validNotEmptyString },
+        ldapBindPwd: { value: "", valid: CONFIG.validNotEmptyString },
+        ldapBase: { value: "", valid: CONFIG.validNotEmptyString },
+        database: { value: "", valid: CONFIG.validNotEmptyString }
+    });
+
+const path = require('path');
+const fs = require('fs');
+const Router = require('node-simple-router');
+const http = require('http');
+const Security = require('craftlabhttpserver/src/security.js');
+const RouterUtils = require('craftlabhttpserver/src/routerUtils.js').RouterUtils;
+
+function App() {
+    this.router = new Router({ static_route: __dirname+"/static/" });
+    this.routerUtils = new RouterUtils(this);
+    this.databaseHelper = require('craftlabhttpserver/src/databaseHelper.js').DatabaseHelper;
+}
+
+App.prototype.init = async function() {
+    [
+        "craftlabhttpserver/router/mdi.js",
+        "craftlabhttpserver/router/bootstrap.js",
+    ].forEach(i => require(i).register(this));
+    await this.databaseHelper.init();
+}
+
+App.prototype.run = async function() {
+    http.createServer(this.router).listen(CONFIG.port);
+}
+
+let app = new App();
+app.init().then(() => app.run());
+

+ 6 - 6
main.js

@@ -1,6 +1,6 @@
 #!/bin/node
 
-const CONFIG = require('./src/config.js');
+const CONFIG = require('craftlabhttpserver/src/config.js');
 CONFIG.Initialize(
     {
         port: { value: 80, valid: CONFIG.validNumber },
@@ -16,19 +16,19 @@ const path = require('path');
 const fs = require('fs');
 const Router = require('node-simple-router');
 const http = require('http');
-const Security = require('./src/security.js');
-const RouterUtils = require('./src/routerUtils.js').RouterUtils;
+const Security = require('craftlabhttpserver/src/security.js');
+const RouterUtils = require('craftlabhttpserver/src/routerUtils.js').RouterUtils;
 
 function App() {
     this.router = new Router({ static_route: __dirname+"/static/" });
     this.routerUtils = new RouterUtils(this);
-    this.databaseHelper = require('./src/databaseHelper.js').DatabaseHelper;
+    this.databaseHelper = require('craftlabhttpserver/src/databaseHelper.js').DatabaseHelper;
 }
 
 App.prototype.init = async function() {
     [
-        "./router/mdi.js",
-        "./router/bootstrap.js",
+        "craftlabhttpserver/router/mdi.js",
+        "craftlabhttpserver/router/bootstrap.js",
     ].forEach(i => require(i).register(this));
     await this.databaseHelper.init();
 }