saloe 0.0.4 → 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.
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "demo-listener",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "server.js",
6
+ "scripts": {
7
+ "watch:dev": "ENV=dev vite build --watch",
8
+ "watch:qa": "ENV=qa vite build --watch",
9
+ "watch:prod": "ENV=prod vite build --watch",
10
+ "build:dev": "ENV=dev vite build",
11
+ "build:qa": "ENV=qa vite build",
12
+ "build:prod": "ENV=prod vite build",
13
+ "local:dev": "wrangler dev --env=dev",
14
+ "local:qa": "wrangler dev --env=qa",
15
+ "local:prod": "wrangler dev --env=prod",
16
+ "deploy:dev": "npm run build:dev && wrangler deploy --env=dev",
17
+ "deploy:qa": "npm run build:qa && wrangler deploy --env=qa",
18
+ "deploy:prod": "npm run build:prod && wrangler deploy --env=prod",
19
+ "build-worker:dev": "wrangler deploy --dry-run --outdir=dist-worker"
20
+ },
21
+ "keywords": [],
22
+ "author": "",
23
+ "license": "ISC",
24
+ "devDependencies": {
25
+ "@cloudflare/kv-asset-handler": "^0.3.4",
26
+ "saloe": "^0.0.4",
27
+ "vite": "^5.4.3"
28
+ }
29
+ }
@@ -0,0 +1,5 @@
1
+ const input = ({ e, srcElement }) => {
2
+ console.log('--- value =', srcElement?.value)
3
+ }
4
+
5
+ export { input }
@@ -0,0 +1,5 @@
1
+ const load = ({ e, srcElement }) => {
2
+ console.log('--- load')
3
+ }
4
+
5
+ export { load }
@@ -0,0 +1,6 @@
1
+ const submit = ({ e, srcElement }) => {
2
+ e.preventDefault()
3
+ console.log('--- submit 2')
4
+ }
5
+
6
+ export { submit }
@@ -0,0 +1,94 @@
1
+ import { findPatternFromUrl, getRedirectResponse, getForbiddenResponse, getRoute, getNotFoundResponse, getServerOnlyResponse } from 'saloe/router'
2
+ import { getStaticResponse } from 'saloe/cloudflare-worker'
3
+ import { addRoute } from 'saloe/router'
4
+ import { html, stream } from 'saloe/html'
5
+ import { LISTENER_SCRIPT } from 'saloe/actions'
6
+ import { listener, getScriptListener } from 'saloe/listener'
7
+
8
+ import manifestJSON from '__STATIC_CONTENT_MANIFEST'
9
+
10
+
11
+ const isRedirectableCallback = ({ pathname }) => {
12
+ return pathname !== '/' && pathname.endsWith('/')
13
+ }
14
+
15
+ const isForbiddenCallback = ({ request }) => {
16
+ const forbiddenURLs = []
17
+ return forbiddenURLs.find((pathname) => request?.url?.endsWith(pathname))
18
+ }
19
+
20
+ const isServerOnlyCallback = ({ request }) => {
21
+ const serverOnlyURLs = []
22
+ return serverOnlyURLs?.find((pathname) => request?.url?.endsWith(pathname))
23
+ }
24
+
25
+
26
+ (() => {
27
+ addRoute({
28
+ pathname: '/',
29
+ route: ({ request, env }) => {
30
+ return stream({
31
+ head: () => html`
32
+ <meta charset="UTF-8">
33
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
34
+ <title>Cloudflare Worker Server</title>
35
+ `,
36
+ body: () => html`
37
+
38
+ <form
39
+ on-submit="submit"
40
+ >
41
+ <h1
42
+ on-load="load"
43
+ >
44
+ Hello world!
45
+ </h1>
46
+ <input
47
+ type="text"
48
+ on-input="input"
49
+ />
50
+ <button type="submit">Submit!</button>
51
+ </form>
52
+ `,
53
+ scripts: () => html`
54
+ ${getScriptListener()}
55
+ <script>
56
+ console.log('Hello world!')
57
+ </script>
58
+ `,
59
+ env,
60
+ })
61
+ }
62
+ })
63
+
64
+ })()
65
+
66
+ const handleFetch = async ({ request, env, ctx }) => {
67
+ const url = new URL(request.url)
68
+ const { origin, pathname } = url
69
+
70
+ const pattern = findPatternFromUrl({ url })
71
+
72
+ const redirectResult = getRedirectResponse({ origin, pathname, isRedirectableCallback })
73
+ if (redirectResult?.response) return redirectResult.response
74
+
75
+ const forbiddenResult = getForbiddenResponse({ origin, request, isForbiddenCallback })
76
+ if (forbiddenResult?.response) return forbiddenResult.response
77
+
78
+ const serverOnlyResult = getServerOnlyResponse({ origin, request, isServerOnlyCallback })
79
+ if (serverOnlyResult?.response) return serverOnlyResult.response
80
+
81
+ const route = getRoute({ pathname: pattern?.pathname })
82
+ const routeResult = route ? await route({ request, pattern, env }) : null
83
+ if (routeResult?.response) return routeResult.response
84
+
85
+ const staticResult = await getStaticResponse({ request, waitUntil: ctx.waitUntil.bind(ctx), manifestJSON, env })
86
+ if (staticResult?.response) return staticResult?.response
87
+
88
+ const notFoundResult = await getNotFoundResponse({ request })
89
+ return notFoundResult?.response
90
+ }
91
+
92
+ export default {
93
+ fetch: (request, env, ctx) => handleFetch({ request, env, ctx })
94
+ }
@@ -0,0 +1,25 @@
1
+ import { defineConfig } from 'vite'
2
+
3
+
4
+ export default defineConfig({
5
+ define: {
6
+ __ENV__: `'${process.env.ENV}'`,
7
+ __BUILD_TIME__: `'${new Date().toISOString()}'`,
8
+ __APP_NAME__: `'demo-server'`,
9
+ },
10
+ plugins: [],
11
+ build: {
12
+ outDir: './dist',
13
+ manifest: true,
14
+ emptyOutDir: true,
15
+ minify: false,
16
+ rollupOptions: {
17
+ input: {},
18
+ output: {
19
+ entryFileNames: `[name].js`,
20
+ chunkFileNames: `[name].js`,
21
+ assetFileNames: `[name].[ext]`,
22
+ },
23
+ },
24
+ },
25
+ })
@@ -0,0 +1,35 @@
1
+ name = "demo-actions"
2
+ main = "server.js"
3
+ compatibility_date = "2022-11-01"
4
+ compatibility_flags = ["transformstream_enable_standard_constructor", "streams_enable_constructors"]
5
+ minify = false
6
+ #node_compat = true
7
+
8
+ [site]
9
+ bucket = "./public"
10
+
11
+ [env]
12
+
13
+ [env.prod]
14
+ experimental-local = true
15
+
16
+ [env.prod.vars]
17
+ IS_CLOUDFLARE_WORKER = true
18
+ ENV = "prod"
19
+ APP_NAME = "demo-actions"
20
+
21
+ [env.qa]
22
+ experimental-local = true
23
+
24
+ [env.qa.vars]
25
+ IS_CLOUDFLARE_WORKER = true
26
+ ENV = "qa"
27
+ APP_NAME = "demo-actions"
28
+
29
+ [env.dev]
30
+ experimental-local = true
31
+
32
+ [env.dev.vars]
33
+ IS_CLOUDFLARE_WORKER = true
34
+ ENV = "dev"
35
+ APP_NAME = "demo-actions"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saloe",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Tools for making web development easy and efficient",
5
5
  "scripts": {
6
6
  "build": "vite build",