1 let EmailJSCache = require('@ndcode/emailjs_cache')
2 let ZettairCache = require('@ndcode/zettair_cache')
3 let assert = require('assert')
5 let CustomSite = function(resources, root, options, prev_site) {
6 if (!this instanceof CustomSite)
7 throw Error('CustomSite is a constructor')
8 _jst_server.Site.call(this, resources, root, options, prev_site)
10 this.emailjs_cache = undefined
11 this.zettair_cache = undefined
14 CustomSite.prototype = Object.create(_jst_server.Site.prototype)
16 CustomSite.prototype.start = async function() {
17 await _jst_server.Site.prototype.start.call(this)
19 assert(this.emailjs_cache === undefined)
20 this.emailjs_cache = await this.resources.ref(
22 async () => new EmailJSCache(true)
25 assert(this.zettair_cache === undefined)
26 this.zettair_cache = await this.resources.ref(
28 async () => new ZettairCache(true)
32 CustomSite.prototype.stop = async function() {
33 await _jst_server.Site.prototype.stop.call(this)
35 assert(this.emailjs_cache !== undefined)
36 await this.resources.unref('emailjs_cache')
38 assert(this.zettair_cache !== undefined)
39 await this.resources.unref('zettair_cache')
42 CustomSite.prototype.kick = async function() {
43 await _jst_server.Site.prototype.kick.call(this)
45 assert(this.emailjs_cache !== undefined)
46 this.emailjs_cache.kick()
48 assert(this.zettair_cache !== undefined)
49 this.zettair_cache.kick()
52 CustomSite.prototype.get_emailjs = function(pathname) {
53 return /*await*/ this.emailjs_cache.get(this.root + pathname)
56 CustomSite.prototype.get_zettair = function(pathname) {
57 return /*await*/ this.zettair_cache.get(this.root + pathname)
60 CustomSite.prototype.respond = async function(env) {
62 env.parsed_url.pathname === '/node_modules' ||
63 env.parsed_url.pathname.slice(0, 14) === '/node_modules/' ||
64 env.parsed_url.pathname === '/package.json' ||
65 env.parsed_url.pathname === '/package-lock.json'
67 this.die(env, `banned file ${env.parsed_url.pathname}`)
70 return /*await*/ _jst_server.Site.prototype.respond.call(this, env)
73 return async (resources, root, prev_site) => new CustomSite(