let MinHTMLCache = require('@ndcode/min_html_cache')
let MinSVGCache = require('@ndcode/min_svg_cache')
let Resources = require('./Resources')
+let SassCSSCache = require('@ndcode/sass_css_cache')
let TextCache = require('@ndcode/text_cache')
let ZipCache = require('@ndcode/zip_cache')
let assert = require('assert')
async () => new MinSVGCache(true)
)
+ assert(this.sass_css_cache === undefined)
+ this.sass_css_cache = await this.resources.ref(
+ `sass_css_cache:${this.root}`,
+ async () => new SassCSSCache(this.root, true)
+ )
+
assert(this.text_cache === undefined)
this.text_cache = await this.resources.ref(
'text_cache',
assert(this.min_svg_cache !== undefined)
await this.resources.unref('min_svg_cache')
+ assert(this.sass_css_cache !== undefined)
+ await this.resources.unref(`sass_css_cache:${this.root}`)
+
assert(this.text_cache !== undefined)
await this.resources.unref('text_cache')
assert(this.min_svg_cache !== undefined)
this.min_svg_cache.kick()
+ assert(this.sass_css_cache !== undefined)
+ this.sass_css_cache.kick()
+
assert(this.text_cache !== undefined)
this.text_cache.kick()
return /*await*/ this.min_svg_cache.get(this.root + pathname)
}
+Site.prototype.get_sass_css = function(pathname) {
+ return /*await*/ this.sass_css_cache.get(this.root + pathname)
+}
+
Site.prototype.get_text = function(pathname) {
return /*await*/ this.text_cache.get(this.root + pathname)
}
Site.prototype.serve_less_css = async function(env, pathname) {
if (pathname.slice(-9) !== '.css.less')
return false
-
- let data
+
+ let data
try {
data = await this.less_css_cache.get(pathname)
}
Site.prototype.serve_min_css = async function(env, pathname) {
if (pathname.slice(-8) !== '.css.min')
return false
-
- let data
+
+ let data
try {
data = await this.min_css_cache.get(pathname)
}
Site.prototype.serve_min_html = async function(env, pathname) {
if (pathname.slice(-9) !== '.html.min')
return false
-
- let data
+
+ let data
try {
data = await this.min_html_cache.get(pathname)
}
Site.prototype.serve_min_js = async function(env, pathname) {
if (pathname.slice(-7) !== '.js.min')
return false
-
- let data
+
+ let data
try {
data = await this.min_js_cache.get(pathname)
}
Site.prototype.serve_min_svg = async function(env, pathname) {
if (pathname.slice(-8) !== '.svg.min')
return false
-
- let data
+
+ let data
try {
data = await this.min_svg_cache.get(pathname)
}
return true
}
+Site.prototype.serve_sass_css = async function(env, pathname) {
+ if (
+ pathname.slice(-9) !== '.css.sass' &&
+ pathname.slice(-9) !== '.css.scss'
+ )
+ return false
+
+ let data
+ try {
+ data = await this.sass_css_cache.get(pathname)
+ }
+ catch (err) {
+ if (!(err instanceof Error) || err.code !== 'ENOENT')
+ throw err
+ return false
+ }
+ this.serve(env, 200, data, 'sass_css')
+ return true
+}
+
Site.prototype.serve_fs = async function(env, pathname) {
// see serve_internal()
// since the file may be huge we need to cache it for as long as reasonable
)
env.response.setHeader('Accept-Ranges', 'bytes')
env.response.setHeader('Content-Length', end - start)
-
+
// create video read stream for this particular chunk
stream = fs.createReadStream(pathname, {start: start, end: end - 1})
}
}
Site.prototype.serve_zip = async function(env, zipname, pathname) {
- let zip
+ let zip
try {
zip = await this.zip_cache.get(zipname)
}
return
if (await this.serve_min_svg(env, pathname + '.min'))
return
+ if (await this.serve_sass_css(env, pathname + '.sass'))
+ return
+ if (await this.serve_sass_css(env, pathname + '.scss'))
+ return
if (await this.serve_fs(env, pathname))
return
this.die(env, `file not found ${env.parsed_url.pathname}`)