MCPcopy
hub / github.com/CodeboxIDE/codebox / setup

Function setup

core/cb.offline/main.js:9–68  ·  view source on GitHub ↗
(options, imports, register)

Source from the content-addressed store, hash-verified

7var crc = require('crc');
8
9function setup(options, imports, register) {
10 var server = imports.server;
11 var addons = imports.addons
12 var logger = imports.logger.namespace("offline");
13
14 var manifest = new Manifest();
15 var startTime = Date.now();
16
17 // Disable auth for the manifest file
18 server.disableAuth("/manifest.appcache");
19
20 // Generate manifest
21 server.app.get("/manifest.appcache", function(req, res, next) {
22 res.header("Content-Type", "text/cache-manifest");
23
24 addons.list()
25 .then(function(installedAddons) {
26 var revision = pkg.version+"-"+crc.hex32(crc.crc32(_.map(installedAddons, function(addon, addonName) {
27 return addonName+":"+addon.infos.version;
28 }).sort().join("-")));
29
30 if (options.dev) revision = revision+"-"+startTime;
31
32 // Clear manifest
33 return manifest.clear(revision);
34 })
35 .then(function() {
36 // Add network
37 manifest.add("NETWORK", [
38 '*'
39 ]);
40
41 // Add static files
42 return manifest.addFolder(path.resolve(__dirname + '/../../client/build'), './', null, [
43 "index.html"
44 ]);
45 })
46 .then(function() {
47 // Add addons
48 return addons.list().then(function(addons) {
49 return Q.all(_.map(addons, function(addon) {
50 // Add network resources
51 manifest.add("NETWORK", addon.network());
52
53 // Addon cached resources
54 return Q.all(_.map(addon.resources(), function(resource) {
55 return manifest.addFolder(addon.root, path.join("static/addons/", addon.infos.name), resource);
56 }));
57 }));
58 });
59 }).then(function() {
60 return manifest.content();
61 }).then(function(content) {
62 res.send(content);
63 }, next);
64 });
65
66 // Register

Callers

nothing calls this directly

Calls 2

registerFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected