instaserve 0.1.12 → 0.1.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.
- package/README.md +9 -5
- package/module.mjs +1 -1
- package/package.json +1 -1
- package/routes.mjs +5 -5
- package/server.mjs +2 -2
package/README.md
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
# instaserve
|
|
2
2
|
Instant web stack
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
In any folder:
|
|
5
|
+
|
|
6
|
+
> npx instaserve
|
|
5
7
|
Starts a server in the current directory
|
|
6
|
-
Creates an example routes.mjs file if none exists
|
|
7
8
|
Create a public folder and add files for static file serving
|
|
8
9
|
|
|
10
|
+
> npx instaserve create
|
|
11
|
+
Creates an example routes.mjs file if none exists
|
|
12
|
+
|
|
9
13
|
> npm run deno (deno)
|
|
10
14
|
Starts a deno server using routes.mjs and static serving
|
|
11
15
|
|
|
12
16
|
> npm run bun (bun)
|
|
13
17
|
Starts a bun server
|
|
14
18
|
|
|
15
|
-
>
|
|
16
|
-
|
|
19
|
+
> port=8080 routes=myroutes.mjs npx instaserve
|
|
20
|
+
Use custom port and routes file
|
|
17
21
|
|
|
18
22
|
###Script usage
|
|
19
23
|
````
|
|
20
24
|
import serve from 'instaserve'
|
|
21
25
|
serve({
|
|
22
26
|
|
|
23
|
-
// routes prefixed with _ run on every request
|
|
27
|
+
// routes prefixed with "_" run on every request
|
|
24
28
|
|
|
25
29
|
_log: (r, s) => console.log(r.method, r.url),
|
|
26
30
|
_example: (r, s) => console.log('returning a falsy value (above) will stop processing'),
|
package/module.mjs
CHANGED
|
@@ -41,7 +41,7 @@ export default function (routes, port = 3000) {
|
|
|
41
41
|
})
|
|
42
42
|
}).listen(process.env.port || port)
|
|
43
43
|
|
|
44
|
-
console.log('started on ' + (process.env.port || port))
|
|
44
|
+
console.log('started on: ' + (process.env.port || port) + ', using routes: ' + Object.keys(routes))
|
|
45
45
|
|
|
46
46
|
return {
|
|
47
47
|
routes: routes,
|
package/package.json
CHANGED
package/routes.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
_debug: ({method, url}, s) => !console.log(method, url),
|
|
3
|
+
_example: (r, s) => console.log('returning a falsy value (above) will stop the chain'),
|
|
4
|
+
api: (r, s) => 'an example api response'
|
|
5
|
+
}
|
package/server.mjs
CHANGED
|
@@ -5,8 +5,9 @@ import { pathToFileURL } from 'node:url'
|
|
|
5
5
|
import { resolve } from 'node:path'
|
|
6
6
|
import fs from 'node:fs'
|
|
7
7
|
const routesfile = resolve(process.env.routes || 'routes.mjs')
|
|
8
|
+
const [npx, instaserve, cmd] = process.argv
|
|
8
9
|
|
|
9
|
-
if (!fs.existsSync(routesfile)) {
|
|
10
|
+
if (cmd === 'create' && !fs.existsSync(routesfile)) {
|
|
10
11
|
fs.writeFileSync(routesfile, `export default {
|
|
11
12
|
_debug: ({method, url}, s) => !console.log(method, url),
|
|
12
13
|
_example: (r, s) => console.log('returning a falsy value (above) will stop the chain'),
|
|
@@ -15,6 +16,5 @@ if (!fs.existsSync(routesfile)) {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const routesurl = pathToFileURL(routesfile).href
|
|
18
|
-
console.log(routesurl)
|
|
19
19
|
const routes = (await import(routesurl)).default
|
|
20
20
|
server(routes, process.env.port)
|