summaryrefslogtreecommitdiff
path: root/src/node/hooks/express/static.js
diff options
context:
space:
mode:
authorMatthias Bartelmeß <mba@fourplusone.de>2012-03-13 19:40:33 +0100
committerMatthias Bartelmeß <mba@fourplusone.de>2012-03-13 19:40:33 +0100
commit70940521f2cdc3cdb3361bd148e141f43505ee4d (patch)
tree96eb9974ee057b9fc3c8947d33bdd1601de8cd30 /src/node/hooks/express/static.js
parentcfb58a80a30486156a15515164c9c0f4647f165b (diff)
parentcccd8a923cfa21c7e248a2a5fcffa54caf512e0b (diff)
downloadetherpad-lite-70940521f2cdc3cdb3361bd148e141f43505ee4d.zip
Merge branch 'develop' of git://github.com/Pita/etherpad-lite
Diffstat (limited to 'src/node/hooks/express/static.js')
-rw-r--r--src/node/hooks/express/static.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js
new file mode 100644
index 00000000..e8f9afbb
--- /dev/null
+++ b/src/node/hooks/express/static.js
@@ -0,0 +1,42 @@
+var path = require('path');
+var minify = require('../../utils/Minify');
+var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
+var CachingMiddleware = require('../../utils/caching_middleware');
+var settings = require("../../utils/Settings");
+var Yajsml = require('yajsml');
+var fs = require("fs");
+var ERR = require("async-stacktrace");
+
+exports.expressCreateServer = function (hook_name, args, cb) {
+ // Cache both minified and static.
+ var assetCache = new CachingMiddleware;
+ args.app.all('/(javascripts|static)/*', assetCache.handle);
+
+ // Minify will serve static files compressed (minify enabled). It also has
+ // file-specific hacks for ace/require-kernel/etc.
+ args.app.all('/static/:filename(*)', minify.minify);
+
+ // Setup middleware that will package JavaScript files served by minify for
+ // CommonJS loader on the client-side.
+ var jsServer = new (Yajsml.Server)({
+ rootPath: 'javascripts/src/'
+ , rootURI: 'http://localhost:' + settings.port + '/static/js/'
+ , libraryPath: 'javascripts/lib/'
+ , libraryURI: 'http://localhost:' + settings.port + '/static/plugins/'
+ });
+
+ var StaticAssociator = Yajsml.associators.StaticAssociator;
+ var associations =
+ Yajsml.associators.associationsForSimpleMapping(minify.tar);
+ var associator = new StaticAssociator(associations);
+ jsServer.setAssociator(associator);
+ args.app.use(jsServer);
+
+ // serve plugin definitions
+ // not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js");
+ args.app.get('/pluginfw/plugin-definitions.json', function (req, res, next) {
+ res.header("Content-Type","application/json; charset: utf-8");
+ res.write(JSON.stringify({"plugins": plugins.plugins, "parts": plugins.parts}));
+ res.end();
+ });
+}