instaserve 0.1.14 → 0.1.16
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/bun/http.js +9 -4
- package/deno/server.js +7 -3
- package/package.json +2 -2
- package/server.mjs +19 -19
package/bun/http.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import {existsSync} from 'fs'
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import { pathToFileURL } from 'node:url'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
|
+
const routesfile = resolve(process.env.routes || '../routes.mjs')
|
|
5
|
+
const routesurl = pathToFileURL(routesfile).href
|
|
6
|
+
|
|
7
|
+
const routes = (await import(routesurl)).default
|
|
8
|
+
const port = process.env.port || 3000
|
|
4
9
|
|
|
5
10
|
class s {
|
|
6
11
|
end(s) {
|
|
@@ -9,7 +14,7 @@ class s {
|
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
Bun.serve({
|
|
12
|
-
port:
|
|
17
|
+
port: port,
|
|
13
18
|
async fetch(r) {
|
|
14
19
|
|
|
15
20
|
let url = new URL(r.url).pathname
|
|
@@ -42,4 +47,4 @@ Bun.serve({
|
|
|
42
47
|
}
|
|
43
48
|
})
|
|
44
49
|
|
|
45
|
-
console.log(
|
|
50
|
+
console.log(`Started on: ${port}, using routes: ${Object.keys(routes)}`)
|
package/deno/server.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync } from "https://deno.land/std/fs/mod.ts";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
const routesfile = Deno.env.get('routes') || '../routes.mjs'
|
|
4
|
+
const port = Deno.env.get('port') || 3000
|
|
5
|
+
const routes = (await import(routesfile)).default
|
|
4
6
|
|
|
5
7
|
class s {
|
|
6
8
|
end(s) {
|
|
@@ -32,4 +34,6 @@ Deno.serve(async (r) => {
|
|
|
32
34
|
|
|
33
35
|
return new Response('', { status: 404 })
|
|
34
36
|
|
|
35
|
-
}, {port:
|
|
37
|
+
}, {port: port})
|
|
38
|
+
|
|
39
|
+
console.log(`routes: ${Object.keys(routes)}`)
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instaserve",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Instant web stack",
|
|
5
5
|
"main": "module.mjs",
|
|
6
6
|
"bin": "./server.mjs",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "node server.mjs",
|
|
9
|
-
"deno": "deno run --unstable --allow-net --allow-read deno/server.js",
|
|
9
|
+
"deno": "deno run --allow-env --unstable --allow-net --allow-read deno/server.js",
|
|
10
10
|
"bun": "bun run bun/http.js",
|
|
11
11
|
"test": "node --no-warnings test.mjs"
|
|
12
12
|
}
|
package/server.mjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
#!/usr/bin/
|
|
2
|
-
|
|
3
|
-
import server from './module.mjs'
|
|
4
|
-
import { pathToFileURL } from 'node:url'
|
|
5
|
-
import { resolve } from 'node:path'
|
|
6
|
-
import fs from 'node:fs'
|
|
7
|
-
const routesfile = resolve(process.env.routes || 'routes.mjs')
|
|
8
|
-
const [npx, instaserve, cmd] = process.argv
|
|
9
|
-
|
|
10
|
-
if (cmd === 'create' && !fs.existsSync(routesfile)) {
|
|
11
|
-
fs.writeFileSync(routesfile, `export default {
|
|
12
|
-
_debug: ({method, url}, s) => !console.log(method, url),
|
|
13
|
-
_example: (r, s) => console.log('returning a falsy value (above) will stop the chain'),
|
|
14
|
-
api: (r, s) => 'an example api response'
|
|
15
|
-
}`)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const routesurl = pathToFileURL(routesfile).href
|
|
19
|
-
const routes = (await import(routesurl)).default
|
|
1
|
+
#!/usr/local/bin/node
|
|
2
|
+
|
|
3
|
+
import server from './module.mjs'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
import { resolve } from 'node:path'
|
|
6
|
+
import fs from 'node:fs'
|
|
7
|
+
const routesfile = resolve(process.env.routes || 'routes.mjs')
|
|
8
|
+
const [npx, instaserve, cmd] = process.argv
|
|
9
|
+
|
|
10
|
+
if (cmd === 'create' && !fs.existsSync(routesfile)) {
|
|
11
|
+
fs.writeFileSync(routesfile, `export default {
|
|
12
|
+
_debug: ({method, url}, s) => !console.log(method, url),
|
|
13
|
+
_example: (r, s) => console.log('returning a falsy value (above) will stop the chain'),
|
|
14
|
+
api: (r, s) => 'an example api response'
|
|
15
|
+
}`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const routesurl = pathToFileURL(routesfile).href
|
|
19
|
+
const routes = (await import(routesurl)).default
|
|
20
20
|
server(routes, process.env.port)
|