summaryrefslogtreecommitdiff
path: root/alarm/node_modules/node-forge/nodejs/server.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-10-18 08:59:09 +0200
committerMinteck <contact@minteck.org>2022-10-18 08:59:09 +0200
commit2c4ae43e688a9873e86211ea0e7aeb9ba770dd77 (patch)
tree17848d95522dab25d3cdeb9c4a6450e2a234861f /alarm/node_modules/node-forge/nodejs/server.js
parent108525534c28013cfe1897c30e4565f9893f3766 (diff)
downloadpluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.gz
pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.bz2
pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.zip
Update
Diffstat (limited to 'alarm/node_modules/node-forge/nodejs/server.js')
-rw-r--r--alarm/node_modules/node-forge/nodejs/server.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/alarm/node_modules/node-forge/nodejs/server.js b/alarm/node_modules/node-forge/nodejs/server.js
new file mode 100644
index 0000000..175bd56
--- /dev/null
+++ b/alarm/node_modules/node-forge/nodejs/server.js
@@ -0,0 +1,46 @@
+var PATH = require('path');
+var express = require('express');
+var PORT = 8083;
+
+exports.main = function(callback) {
+ try {
+ var app = express();
+
+ mountStaticDir(app, /^\/forge\/(.*)$/, PATH.join(__dirname, '../js'));
+ mountStaticDir(app, /^\/test\/(.*)$/, PATH.join(__dirname, 'test'));
+ mountStaticDir(app, /^\/mocha\/(.*)$/, PATH.join(__dirname, 'node_modules/mocha'));
+ mountStaticDir(app, /^\/chai\/(.*)$/, PATH.join(__dirname, 'node_modules/chai'));
+ app.get(/^\//, express.static(PATH.join(__dirname, 'ui')));
+
+ var server = app.listen(PORT);
+
+ console.log('open http://localhost:' + PORT + '/');
+
+ return callback(null, {
+ server: server,
+ port: PORT
+ });
+ } catch(err) {
+ return callback(err);
+ }
+};
+
+function mountStaticDir(app, route, path) {
+ app.get(route, function(req, res, next) {
+ var originalUrl = req.url;
+ req.url = req.params[0];
+ express.static(path)(req, res, function() {
+ req.url = originalUrl;
+ return next.apply(null, arguments);
+ });
+ });
+}
+
+if(require.main === module) {
+ exports.main(function(err) {
+ if(err) {
+ console.error(err.stack);
+ process.exit(1);
+ }
+ });
+}