instaserve 0.0.2 → 0.0.5
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.
- package/index.mjs +7 -3
- package/package.json +1 -1
- package/routes.mjs +2 -2
- package/vastdb.mjs +1 -0
package/index.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import http from 'node:http'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
if (!fs.existsSync(`${process.cwd()}/routes.mjs`))
|
|
4
|
+
fs.copyFileSync('./routes.mjs', `${process.cwd()}/routes.mjs`)
|
|
2
5
|
const routes = (await import(`${process.cwd()}/routes.mjs`)).default
|
|
3
6
|
const VastDB = (await import(`./vastdb.mjs`)).default
|
|
4
7
|
const db = new VastDB(routes)
|
|
5
|
-
console.log(db.filename,
|
|
8
|
+
console.log(db.filename, routes)
|
|
6
9
|
|
|
7
10
|
http
|
|
8
11
|
.createServer(async (r, s) => {
|
|
@@ -14,11 +17,12 @@ http
|
|
|
14
17
|
data = JSON.parse(data);
|
|
15
18
|
} catch { }
|
|
16
19
|
});
|
|
20
|
+
s.endJSON = o => s.end(JSON.stringify(o))
|
|
17
21
|
const midware = Object.keys(routes)
|
|
18
22
|
.filter((k) => k.startsWith('_'))
|
|
19
|
-
.map((k) => routes[k]({ r, s, data }));
|
|
23
|
+
.map((k) => routes[k]({ r, s, data, db }));
|
|
20
24
|
if (midware.includes(true)) return;
|
|
21
|
-
if (routes[r.url]) return routes[r.url]({ r, s, data });
|
|
25
|
+
if (routes[r.url]) return routes[r.url]({ r, s, data, db });
|
|
22
26
|
else s.writeHead(404).end()
|
|
23
27
|
} catch (e) {
|
|
24
28
|
console.log(e);
|
package/package.json
CHANGED
package/routes.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
_debug: ({ r, s }) => console.log(r.url, r.method),
|
|
3
|
-
'/': ({ s }) => s.
|
|
2
|
+
_debug: ({ r, s, db }) => console.log(r.url, r.method),
|
|
3
|
+
'/': ({ s }) => s.endJSON({ message: 'hello index' }),
|
|
4
4
|
'tables': name => ([k, v]) => k.match(`${name}:`)
|
|
5
5
|
}
|