this.socket_io.attach(server)
}
-Server.prototype.get_email = function(path) {
+Server.prototype.get_email = function(pathname) {
return this.build_cache_email.get(
- path,
+ pathname,
async result => {
- let text = await fs_readFile(path, {encoding: 'utf-8'})
- console.log('getting', path, 'as email')
+ let text = await fs_readFile(pathname, {encoding: 'utf-8'})
+ console.log('getting', pathname, 'as email')
result.value = emailjs.server.connect(JSON.parse(text))
}
)
// this is for read-only JSON files
// they will be reloaded from disk if modified
-Server.prototype.get_json = function(path) {
+Server.prototype.get_json = function(pathname) {
return this.build_cache_json.get(
- path,
+ pathname,
async result => {
- let text = await fs_readFile(path, {encoding: 'utf-8'})
- console.log('getting', path, 'as json')
+ let text = await fs_readFile(pathname, {encoding: 'utf-8'})
+ console.log('getting', pathname, 'as json')
result.value = JSON.parse(text)
}
)
}
-Server.prototype.get_less = function(dirname, path) {
+Server.prototype.get_jst = function(dirname, pathname) {
+ return js_template(dirname, dirname, pathname, {_server: this})
+}
+
+Server.prototype.get_less = function(dirname, pathname) {
return this.build_cache_less.get(
- path,
+ pathname,
async result => {
- let text = await fs_readFile(path, {encoding: 'utf-8'})
- console.log('getting', path, 'as less')
+ let text = await fs_readFile(pathname, {encoding: 'utf-8'})
+ console.log('getting', pathname, 'as less')
let render = await less.render(
text,
{
//color: true,
//compress: false,
//depends: false,
- filename: path,
+ filename: pathname,
//globalVars: null,
//ieCompat: false,
//insecure: false,
//lint: false,
//math: 0,
//modifyVars: null,
- paths: [this.root + dirname],
+ pathnames: [this.root + dirname],
//plugins: [],
//reUsePluginManager: true,
//rewriteUrls: false,
- rootpath: this.root//,
+ rootpathname: this.root//,
//strictImports: false,
//strictUnits: false,
//urlArgs: ''
)
}
-Server.prototype.get_text = function(path) {
+Server.prototype.get_text = function(pathname) {
return this.build_cache_text.get(
- path,
+ pathname,
async result => {
- let text = await fs_readFile(path, {encoding: 'utf-8'})
- console.log('getting', path, 'as text')
+ let text = await fs_readFile(pathname, {encoding: 'utf-8'})
+ console.log('getting', pathname, 'as text')
result.value = text
}
)
}
-Server.prototype.get_zet = function(path) {
+Server.prototype.get_zet = function(pathname) {
return this.build_cache_zet.get(
- path,
+ pathname,
async result => {
- console.log('getting', path, 'as zet')
+ console.log('getting', pathname, 'as zet')
result.deps = [
- path + '.map.0',
- path + '.param.0',
- path + '.v.0',
- path + '.vocab.0'
+ pathname + '.map.0',
+ pathname + '.param.0',
+ pathname + '.v.0',
+ pathname + '.vocab.0'
]
- result.value = new zetjs.Index(path)
+ result.value = new zetjs.Index(pathname)
}
)
}
-Server.prototype.get_zip = function(path) {
+Server.prototype.get_zip = function(pathname) {
return this.build_cache_zip.get(
- path,
+ pathname,
async result => {
- let zipfile = await yauzl_open(path, {autoClose: false})
- console.log('getting', path, 'as zip')
+ let zipfile = await yauzl_open(pathname, {autoClose: false})
+ console.log('getting', pathname, 'as zip')
let entries = []
await new Promise(
read_stream.pipe(write_stream)
data = await data
- let path = '/' + entries[i].fileName
- console.log('entry path', path, 'size', data.length)
- result.value[path] = data
+ let pathname = '/' + entries[i].fileName
+ console.log('entry pathname', pathname, 'size', data.length)
+ result.value[pathname] = data
}
await zipfile.close()
}
)
}
-Server.prototype.ensure_dir = async function(path) {
+Server.prototype.ensure_dir = async function(pathname) {
try {
- await fs_mkdir(path)
- console.log('create directory', path)
+ await fs_mkdir(pathname)
+ console.log('create directory', pathname)
}
catch (err) {
if (err.code !== 'EEXIST') // should check error type
// this is for read/write JSON files
// they will not be reloaded from disk if modified
-Server.prototype.read_json = async function(path, default_value) {
+Server.prototype.read_json = async function(pathname, default_value) {
return /*await*/ this.json_cache.read(
- path,
+ pathname,
default_value
)
}
-Server.prototype.write_json = async function(path, value, timeout) {
+Server.prototype.write_json = async function(pathname, value, timeout) {
return /*await*/ this.json_cache.write(
- path,
+ pathname,
value,
timeout
)
}
Server.prototype.modify_json =
- async function(path, default_value, modify_func, timeout) {
+ async function(pathname, default_value, modify_func, timeout) {
return /*await*/ this.json_cache.modify(
- path,
+ pathname,
default_value,
modify_func,
timeout
case 'site':
let site_factory
try {
- site_factory = await js_template(
- temp.root,
- temp.root,
- 'site_factory.jst'
- )
+ site_factory = await this.get_jst(temp.root, 'site_factory.jst')
}
catch (err) {
if (err.code !== 'ENOENT') // note: err.code might be undefined
response: response,
request: request,
status: 200,
- server: this,
site: site.object
}
)
)
}
-Site.prototype.get_email = function(path) {
- return /*await*/ this.server.get_email(this.root + path)
+Site.prototype.get_email = function(pathname) {
+ return /*await*/ this.server.get_email(this.root + pathname)
}
-Site.prototype.get_json = function(path) {
- return /*await*/ this.server.get_json(this.root + path)
+Site.prototype.get_json = function(pathname) {
+ return /*await*/ this.server.get_json(this.root + pathname)
}
-Site.prototype.get_less = function(dirname, path) {
- return /*await*/ this.server.get_less(this.root + dirname, this.root + path)
+Site.prototype.get_jst = function(pathname) {
+ return /*await*/ this.server.get_jst(this.root, this.root + pathname)
}
-Site.prototype.get_text = function(path) {
- return /*await*/ this.server.get_text(this.root + path)
+Site.prototype.get_less = function(pathname) {
+ return /*await*/ this.server.get_less(this.root, this.root + pathname)
}
-Site.prototype.get_zet = function(path) {
- return /*await*/ this.server.get_zet(this.root + path)
+Site.prototype.get_text = function(pathname) {
+ return /*await*/ this.server.get_text(this.root + pathname)
}
-Site.prototype.get_zip = function(path) {
- return /*await*/ this.server.get_zip(this.root + path)
+Site.prototype.get_zet = function(pathname) {
+ return /*await*/ this.server.get_zet(this.root + pathname)
+}
+Site.prototype.get_zip = function(pathname) {
+ return /*await*/ this.server.get_zip(this.root + pathname)
}
-Site.prototype.ensure_dir = async function(path) {
- return /*await*/ this.server.ensure_dir(this.root + path)
+Site.prototype.ensure_dir = async function(pathname) {
+ return /*await*/ this.server.ensure_dir(this.root + pathname)
}
// this is for read/write JSON files
// they will not be reloaded from disk if modified
-Site.prototype.read_json = async function(path, default_value) {
+Site.prototype.read_json = async function(pathname, default_value) {
return /*await*/ this.server.read_json(
- this.root + path,
+ this.root + pathname,
default_value
)
}
-Site.prototype.write_json = async function(path, value, timeout) {
+Site.prototype.write_json = async function(pathname, value, timeout) {
return /*await*/ this.server.write_json(
- this.root + path,
+ this.root + pathname,
value,
timeout
)
}
Site.prototype.modify_json =
- async function(path, default_value, modify_func, timeout) {
+ async function(pathname, default_value, modify_func, timeout) {
return /*await*/ this.server.modify_json(
- this.root + path,
+ this.root + pathname,
default_value,
modify_func,
timeout
Site.prototype.serve_jst = async function(env, pathname) {
let jst
try {
- jst = await js_template(this.root, this.root, pathname)
+ jst = await this.get_jst(pathname)
}
catch (err) {
if (err.code !== 'ENOENT')
let data
try {
- data = await this.get_less('', pathname)
+ data = await this.get_less(pathname)
}
catch (err) {
if (err.code !== 'ENOENT')