Make /_config/*.jst use ES6 superclass calls, fix failure to await the superclass...
authorNick Downing <nick@ndcode.org>
Wed, 26 Jan 2022 22:50:53 +0000 (09:50 +1100)
committerNick Downing <nick@ndcode.org>
Wed, 26 Jan 2022 22:58:23 +0000 (09:58 +1100)
_config/server.jst
_config/site.jst

index e6ebffc..f0cd853 100644 (file)
@@ -1,4 +1,6 @@
-return async (resources, prev_server) => new _jst_server.Server(
+let jst_server = (await import('@ndcode/jst_server')).default
+
+return async (resources, prev_server) => new jst_server.Server(
   resources,
   {
     hosts: {
index 4e7d2e6..a346221 100644 (file)
@@ -1,13 +1,14 @@
 let assert = require('assert')
 let cookie = require('cookie')
 let crypto = require('crypto')
+let jst_server = (await import('@ndcode/jst_server')).default
 let logjson = (await import('@ndcode/logjson')).default
 //let NodeMailerCache = require('@ndcode/nodemailer_cache')
 let XDate = require('xdate')
 let ZettairCache = require('@ndcode/zettair_cache')
 
 return async (resources, root, prev_site) => {
-  class CustomSite extends _jst_server.Site {
+  class CustomSite extends jst_server.Site {
     constructor(resources, root, options, prev_site) {
       super(resources, root, options, prev_site)
       this.database = undefined
@@ -19,7 +20,7 @@ return async (resources, root, prev_site) => {
     // called when the server starts or the site.jst file is modified
     // in latter case it will carry over the previously created resource objects
     async start() {
-      await _jst_server.Site.prototype.start.call(this)
+      await super.start()
 
       assert(this.database === undefined)
       this.database = await this.resources.ref(
@@ -49,7 +50,7 @@ return async (resources, root, prev_site) => {
     // first and then the stop() method of the old CustomSite object, so that the
     // reference counting can keep the resource objects alive during changeover
     async stop() {
-      await _jst_server.Site.prototype.stop.call(this)
+      await super.stop()
 
       assert(this.database !== undefined)
       await this.resources.unref('database')
@@ -63,7 +64,7 @@ return async (resources, root, prev_site) => {
 
     // called once per second, responsible for cache cleaning and flushing
     async kick() {
-      await _jst_server.Site.prototype.kick.call(this)
+      await super.kick()
 
       assert(this.database !== undefined)
       await this.database.kick()
@@ -169,17 +170,15 @@ return async (resources, root, prev_site) => {
         env.parsed_url.pathname === '/package.json' ||
         env.parsed_url.pathname === '/package-lock.json'
       ) {
-        this.die(env, `banned file ${env.parsed_url.pathname}`)
-        return
+        throw new jst_server.Problem(
+          'Not found',
+          `Banned file \"${env.parsed_url.pathname}\"`,
+          404
+        )
       }
-      return /*await*/ _jst_server.Site.prototype.respond.call(this, env)
+      return /*await*/ super.respond(env)
     }
   }
 
-  return new CustomSite(
-    resources,
-    root,
-    {},
-    prev_site
-  )
+  return new CustomSite(resources, root, {}, prev_site)
 }