aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/app.js')
-rw-r--r--lib/app.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/app.js b/lib/app.js
index e0b4417..0b7784c 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -42,6 +42,8 @@ function App(sbot, config) {
var host1 = /:/.test(this.host) ? '[' + this.host + ']' : this.host
this.baseUrl = 'http://' + host1 + ':' + this.port
+ this.dir = path.join(config.path, conf.dir || 'patchfoo')
+ this.scriptDir = path.join(this.dir, conf.scriptDir || 'script')
var base = conf.base || '/'
this.opts = {
@@ -78,6 +80,9 @@ function App(sbot, config) {
this.about = new About(this, sbot.id, this.follows)
this.serveSsbNpmRegistry = SsbNpmRegistry.respond(this.sbot, this.config)
+ this.mtimes = {}
+ this.getScript = memo({cache: false}, this.getScript)
+
this.monitorBlobWants()
this.navLinks = conf.nav || [
'new',
@@ -1246,3 +1251,22 @@ App.prototype.verifyGitObjectSignature = function (obj, cb) {
})
}
}
+
+App.prototype.getScript = function (filepath, cb) {
+ var filename = path.join(this.scriptDir, filepath)
+ var self = this
+ fs.stat(filename, function (err, stat) {
+ if (err) return cb(err)
+ var resolved = require.resolve(filename)
+ var prevMtime = self.mtimes[resolved]
+ var mtime = stat.mtime.getTime()
+ if (mtime !== prevMtime) {
+ delete require.cache[resolved]
+ self.mtimes[filename] = mtime
+ }
+ var module
+ try { module = require(resolved) }
+ catch(e) { return cb(e) }
+ cb(null, module)
+ })
+}