Use ES6 classes in /_config/site.jst for compatibility with latest jst_server
authorNick Downing <nick@ndcode.org>
Wed, 26 Jan 2022 12:58:48 +0000 (07:58 -0500)
committerNick Downing <nick@ndcode.org>
Wed, 26 Jan 2022 12:58:48 +0000 (07:58 -0500)
_config/site.jst

index 37bcece..c849156 100644 (file)
@@ -2,76 +2,76 @@
 //let ZettairCache = require('@ndcode/zettair_cache')
 let assert = require('assert')
 
-let CustomSite = function(resources, root, options, prev_site) {
-  if (!this instanceof CustomSite)
-    throw Error('CustomSite is a constructor')
-  _jst_server.Site.call(this, resources, root, options, prev_site)
-
-  //this.emailjs_cache = undefined
-  //this.zettair_cache = undefined
-}
-
-CustomSite.prototype = Object.create(_jst_server.Site.prototype)
-
-CustomSite.prototype.start = async function() {
-  await _jst_server.Site.prototype.start.call(this)
-
-  //assert(this.emailjs_cache === undefined)
-  //this.emailjs_cache = await this.resources.ref(
-  //  'emailjs_cache',
-  //  async () => new EmailJSCache(true)
-  //)
-
-  //assert(this.zettair_cache === undefined)
-  //this.zettair_cache = await this.resources.ref(
-  //  'zettair_cache',
-  //  async () => new ZettairCache(true)
-  //)
-}
-
-CustomSite.prototype.stop = async function() {
-  await _jst_server.Site.prototype.stop.call(this)
-
-  //assert(this.emailjs_cache !== undefined)
-  //await this.resources.unref('emailjs_cache')
-
-  //assert(this.zettair_cache !== undefined)
-  //await this.resources.unref('zettair_cache')
-}
-
-CustomSite.prototype.kick = async function() {
-  await _jst_server.Site.prototype.kick.call(this)
-
-  //assert(this.emailjs_cache !== undefined)
-  //this.emailjs_cache.kick()
-
-  //assert(this.zettair_cache !== undefined)
-  //this.zettair_cache.kick()
-}
-
-//CustomSite.prototype.get_emailjs = function(pathname) {
-//  return /*await*/ this.emailjs_cache.get(this.root + pathname)
-//}
-
-//CustomSite.prototype.get_zettair = function(pathname) {
-//  return /*await*/ this.zettair_cache.get(this.root + pathname)
-//}
-
-CustomSite.prototype.respond = async function(env) {
-  if (
-    env.parsed_url.pathname === '/node_modules' ||
-    env.parsed_url.pathname.slice(0, 14) === '/node_modules/' ||
-    env.parsed_url.pathname === '/package.json'
-  ) {
-    this.die(env, `banned file ${env.parsed_url.pathname}`)
-    return
+return async (resources, root, prev_site) => {
+  class CustomSite extends _jst_server.Site {
+    //constructor(resources, root, options, prev_site) {
+    //  super(resources, root, options, prev_site)
+    //
+    //  //this.emailjs_cache = undefined
+    //  //this.zettair_cache = undefined
+    //}
+
+    async start() {
+      await _jst_server.Site.prototype.start.call(this)
+
+      //assert(this.emailjs_cache === undefined)
+      //this.emailjs_cache = await this.resources.ref(
+      //  'emailjs_cache',
+      //  async () => new EmailJSCache(true)
+      //)
+
+      //assert(this.zettair_cache === undefined)
+      //this.zettair_cache = await this.resources.ref(
+      //  'zettair_cache',
+      //  async () => new ZettairCache(true)
+      //)
+    }
+
+    async stop() {
+      await _jst_server.Site.prototype.stop.call(this)
+
+      //assert(this.emailjs_cache !== undefined)
+      //await this.resources.unref('emailjs_cache')
+
+      //assert(this.zettair_cache !== undefined)
+      //await this.resources.unref('zettair_cache')
+    }
+
+    async kick() {
+      await _jst_server.Site.prototype.kick.call(this)
+
+      //assert(this.emailjs_cache !== undefined)
+      //this.emailjs_cache.kick()
+
+      //assert(this.zettair_cache !== undefined)
+      //this.zettair_cache.kick()
+    }
+
+    //get_emailjs(pathname) {
+    //  return /*await*/ this.emailjs_cache.get(this.root + pathname)
+    //}
+
+    //get_zettair(pathname) {
+    //  return /*await*/ this.zettair_cache.get(this.root + pathname)
+    //}
+
+    async respond(env) {
+      if (
+        env.parsed_url.pathname === '/node_modules' ||
+        env.parsed_url.pathname.slice(0, 14) === '/node_modules/' ||
+        env.parsed_url.pathname === '/package.json'
+      ) {
+        this.die(env, `banned file ${env.parsed_url.pathname}`)
+        return
+      }
+      return /*await*/ _jst_server.Site.prototype.respond.call(this, env)
+    }
   }
-  return /*await*/ _jst_server.Site.prototype.respond.call(this, env)
-}
 
-return async (resources, root, prev_site) => new CustomSite(
-  resources,
-  root,
-  {},
-  prev_site
-)
+  return new CustomSite(
+    resources,
+    root,
+    {},
+    prev_site
+  )
+}