instaserve 0.0.11 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +6 -4
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1,15 +1,17 @@
1
1
  import http from 'node:http'
2
2
  import fs from 'node:fs'
3
3
  if (!fs.existsSync(process.cwd() + '/routes.mjs')) {
4
- fs.writeFileSync(process.cwd() + '/routes.mjs', `
5
- export default {
4
+ fs.writeFileSync(process.cwd() + '/routes.mjs', `export default {
6
5
  _debug: ({ r, s, db }) => console.log(r.url, r.method),
7
6
  '/': ({ s }) => s.endJSON({ message: 'hello index' }),
8
7
  'tables': name => ([k, v]) => k.match(name + ':')
9
- }
10
- `)
8
+ }`)
11
9
  }
12
10
  const routes = (await import(`${process.cwd()}/routes.mjs`)).default
11
+ routes['/sw.js'] = e => {
12
+ e.s.writeHead(201, { 'Content-Type': 'application/javascript' })
13
+ e.s.end('self.addEventListener("fetch",e=>{e.respondWith(caches.open("e").then(function(t){return t.match(e.request).then(function(n){return n||fetch(e.request).then(function(n){return e.request.url.match(/\.js$|\.css$/)&&t.put(e.request,n.clone()),n})})}))});')
14
+ }
13
15
  const VastDB = (await import(`./vastdb.mjs`)).default
14
16
  const db = new VastDB(routes)
15
17
  console.log(db.filename, routes)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instaserve",
3
- "version": "0.0.11",
3
+ "version": "0.0.14",
4
4
  "description": "",
5
5
  "main": "index.mjs",
6
6
  "bin": "./index.mjs"