edge-city

#react#js#ssr

git clone https://git.pyrossh.dev/edge-city

edge-city is a next level meta-framework for react that runs only on edge runtimes


ceccf1f — Peter John 2023-03-18T17:41:24+05:30
move to workspace

Generated files not shown: bun.lockb, package-lock.json

.gitignore CHANGED
@@ -1,172 +1 @@
1
- # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2
-
3
- # Logs
4
-
5
- logs
6
- _.log
7
- npm-debug.log_
8
- yarn-debug.log*
9
- yarn-error.log*
10
- lerna-debug.log*
11
- .pnpm-debug.log*
12
-
13
- # Diagnostic reports (https://nodejs.org/api/report.html)
14
-
15
- report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
16
-
17
- # Runtime data
18
-
19
- pids
20
- _.pid
21
- _.seed
22
- \*.pid.lock
23
-
24
- # Directory for instrumented libs generated by jscoverage/JSCover
25
-
26
- lib-cov
27
-
28
- # Coverage directory used by tools like istanbul
29
-
30
- coverage
31
- \*.lcov
32
-
33
- # nyc test coverage
34
-
35
- .nyc_output
36
-
37
- # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
38
-
39
- .grunt
40
-
41
- # Bower dependency directory (https://bower.io/)
42
-
43
- bower_components
44
-
45
- # node-waf configuration
46
-
47
- .lock-wscript
48
-
49
- # Compiled binary addons (https://nodejs.org/api/addons.html)
50
-
51
- build/Release
52
-
53
- # Dependency directories
54
-
55
- node_modules/
1
+ node_modules
56
- jspm_packages/
57
-
58
- # Snowpack dependency directory (https://snowpack.dev/)
59
-
60
- web_modules/
61
-
62
- # TypeScript cache
63
-
64
- \*.tsbuildinfo
65
-
66
- # Optional npm cache directory
67
-
68
- .npm
69
-
70
- # Optional eslint cache
71
-
72
- .eslintcache
73
-
74
- # Optional stylelint cache
75
-
76
- .stylelintcache
77
-
78
- # Microbundle cache
79
-
80
- .rpt2_cache/
81
- .rts2_cache_cjs/
82
- .rts2_cache_es/
83
- .rts2_cache_umd/
84
-
85
- # Optional REPL history
86
-
87
- .node_repl_history
88
-
89
- # Output of 'npm pack'
90
-
91
- \*.tgz
92
-
93
- # Yarn Integrity file
94
-
95
- .yarn-integrity
96
-
97
- # dotenv environment variable files
98
-
99
- .env
100
- .env.development.local
101
- .env.test.local
102
- .env.production.local
103
- .env.local
104
-
105
- # parcel-bundler cache (https://parceljs.org/)
106
-
107
- .cache
108
- .parcel-cache
109
-
110
- # Next.js build output
111
-
112
- .next
113
- out
114
-
115
- # Nuxt.js build / generate output
116
-
117
- .nuxt
118
- dist
119
-
120
- # Gatsby files
121
-
122
- .cache/
123
-
124
- # Comment in the public line in if your project uses Gatsby and not Next.js
125
-
126
- # https://nextjs.org/blog/next-9-1#public-directory-support
127
-
128
- # public
129
-
130
- # vuepress build output
131
-
132
- .vuepress/dist
133
-
134
- # vuepress v2.x temp and cache directory
135
-
136
- .temp
137
- .cache
138
-
139
- # Docusaurus cache and generated files
140
-
141
- .docusaurus
142
-
143
- # Serverless directories
144
-
145
- .serverless/
146
-
147
- # FuseBox cache
148
-
149
- .fusebox/
150
-
151
- # DynamoDB Local files
152
-
153
- .dynamodb/
154
-
155
- # TernJS port file
156
-
157
- .tern-port
158
-
159
- # Stores VSCode versions used for testing VSCode extensions
160
-
161
- .vscode-test
162
-
163
- # yarn v2
164
-
165
- .yarn/cache
166
- .yarn/unplugged
167
- .yarn/build-state.yml
168
- .yarn/install-state.gz
169
- .pnp.\*
170
- .cache
171
- dist
172
- .vercel
README.md DELETED
@@ -1,15 +0,0 @@
1
- # quickstart
2
-
3
- To install dependencies:
4
-
5
- ```bash
6
- bun install
7
- ```
8
-
9
- To run:
10
-
11
- ```bash
12
- bun run index.js
13
- ```
14
-
15
- This project was created using `bun init` in bun v0.5.7. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
package.json CHANGED
@@ -1,24 +1,8 @@
1
1
  {
2
- "name": "quickstart",
2
+ "name": "my-project",
3
- "module": "index.js",
4
- "type": "module",
3
+ "version": "1.0.0",
4
+ "workspaces": ["packages/example", "packages/muffinjs"],
5
5
  "scripts": {
6
- "dev": "bun --hot index.js",
7
- "start": "bun index.js"
6
+ "start": "muffin"
8
- },
9
- "devDependencies": {
10
- "bun-types": "^0.5.0"
11
- },
12
- "dependencies": {
13
- "@blueprintjs/core": "^4.17.6",
14
- "autoprefixer": "^10.4.14",
15
- "postcss": "^8.4.21",
16
- "postcss-custom-media": "^9.1.2",
17
- "postcss-nesting": "^11.2.1",
18
- "postcss-normalize": "^10.0.1",
19
- "react": "18.2.0",
20
- "react-dom": "^18.2.0",
21
- "react-streaming": "^0.3.5",
22
- "zod": "^3.21.0"
23
7
  }
24
8
  }
packages/example/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .cache
2
+ .dist
3
+ node_modules
{components → packages/example/components}/Todo.jsx RENAMED
File without changes
{containers → packages/example/containers}/TodoList.jsx RENAMED
@@ -1,4 +1,4 @@
1
- import Todo from "@/components/Todo.jsx";
1
+ import Todo from "@/example/components/Todo.jsx";
2
2
 
3
3
  const todos = [
4
4
  { id: '1', text: "123" },
jsconfig.json → packages/example/jsconfig.json RENAMED
File without changes
packages/example/main.js ADDED
@@ -0,0 +1,3 @@
1
+ import server from "muffinjs/index.js";
2
+
3
+ export default server;
packages/example/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "quickstart",
3
+ "type": "module",
4
+ "scripts": {
5
+ "dev": "bun --hot main.js"
6
+ },
7
+ "dependencies": {
8
+ "muffinjs": "0.1.0",
9
+ "react": "18.2.0",
10
+ "react-dom": "^18.2.0"
11
+ }
12
+ }
{routes → packages/example/routes}/about/page.css RENAMED
File without changes
{routes → packages/example/routes}/about/page.jsx RENAMED
File without changes
{routes → packages/example/routes}/health/api.js RENAMED
File without changes
{routes → packages/example/routes}/index/page.css RENAMED
File without changes
{routes → packages/example/routes}/index/page.jsx RENAMED
@@ -1,5 +1,5 @@
1
1
  import { useState } from "react";
2
- import { useRouter } from "@/router.js";
2
+ import { useRouter } from "muffinjs/router.js";
3
3
  import TodoList from "@/containers/TodoList.jsx";
4
4
  // import "./index.css";
5
5
 
routes/todos/[id]/api.js → packages/example/routes/todos/[id]/server.js RENAMED
@@ -1,4 +1,4 @@
1
- import tigrisDB from "./db.js.js";
1
+ import tigrisDB from "./db.js.js.js";
2
2
 
3
3
  export const todosCollection = tigrisDB.getCollection("todoItems");
4
4
 
@@ -17,8 +17,9 @@ export const onGet = async (req) => {
17
17
  }
18
18
 
19
19
  export const onPut = async (req) => {
20
+ const item = await req.body();
20
21
  const updated = await todosCollection.insertOrReplaceOne(item);
21
- const data = JSON.stringify(updated);
22
+ const data = JSON.stringify(updated);``
22
23
  return new Response(data, {
23
24
  headers: {
24
25
  "Content-Type": "application/json",
{routes → packages/example/routes}/todos/api.js RENAMED
@@ -1,4 +1,4 @@
1
- import tigrisDB from "./db.js.js";
1
+ import tigrisDB from "./db.js.js.js";
2
2
 
3
3
  export const todosCollection = tigrisDB.getCollection("todoItems");
4
4
 
packages/example/routes/todos/page.css ADDED
@@ -0,0 +1,11 @@
1
+ .home-page {
2
+ padding: 10px;
3
+ background-color: turquoise;
4
+
5
+ & .count {
6
+ color: black;
7
+ padding: 40px;
8
+ font-size: 30px;
9
+ font-weight: 600;
10
+ }
11
+ }
packages/example/routes/todos/page.jsx ADDED
@@ -0,0 +1,16 @@
1
+ import { Suspense } from "react";
2
+ import { useRouter } from "muffinjs/router.js";
3
+ import TodoList from "@/containers/TodoList.jsx";
4
+ // import "./index.css";
5
+
6
+ export default () => {
7
+ const router = useRouter();
8
+ const { data: todos, isRevalidating } = usePromise("/todos");
9
+ return (
10
+ <div className="todos-page">
11
+ <Suspense>
12
+ <TodoList todos={todos} />
13
+ </Suspense>
14
+ </div>
15
+ )
16
+ }
{static → packages/example/static}/favicon.ico RENAMED
File without changes
{static → packages/example/static}/logo192.png RENAMED
File without changes
{static → packages/example/static}/logo512.png RENAMED
File without changes
{static → packages/example/static}/manifest.json RENAMED
File without changes
{static → packages/example/static}/robots.txt RENAMED
File without changes
packages/muffinjs/.gitignore ADDED
@@ -0,0 +1 @@
1
+ node_modules
atom.js → packages/muffinjs/atom.js RENAMED
File without changes
packages/muffinjs/bin/muffin.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import server from "../index.js";
4
+
5
+ Bun.serve(server);
index.js → packages/muffinjs/index.js RENAMED
@@ -1,8 +1,10 @@
1
1
  import './jsxPlugin.js';
2
+ import React from 'react';
2
3
  import path from 'path';
3
4
  import { renderToReadableStream } from 'react-dom/server';
4
5
  import { routerAtom } from './router.js';
6
+
5
- import packageJson from "./package.json";
7
+ console.log("running in", process.cwd());
6
8
 
7
9
  const transpiler = new Bun.Transpiler({
8
10
  loader: "jsx",
@@ -15,11 +17,6 @@ const renderApi = async (route, req) => {
15
17
  console.log('routeImport', routeImport);
16
18
  }
17
19
 
18
- const deps = Object.keys(packageJson.dependencies).reduce((acc, dep) => {
19
- acc[dep] = `https://esm.sh/${dep}@${packageJson.dependencies[dep]}?dev`;
20
- return acc;
21
- }, {})
22
-
23
20
  const renderPage = async (filePath, url, params) => {
24
21
  const query = {};
25
22
  for (const key of url.searchParams.keys()) {
@@ -30,9 +27,14 @@ const renderPage = async (filePath, url, params) => {
30
27
  params: params,
31
28
  pathname: url.pathname,
32
29
  }
33
- console.log('filePath', filePath);
34
30
  routerAtom.update(() => initialRouteValue);
35
31
  const routeImport = await import(filePath);
32
+ const packageJson = await import(path.join(process.cwd(), "package.json"));
33
+ const dependencies = packageJson.default.dependencies;
34
+ const imports = Object.keys(dependencies).reduce((acc, dep) => {
35
+ acc[dep] = `https://esm.sh/${dep}@${dependencies[dep]}?dev`;
36
+ return acc;
37
+ }, {})
36
38
  const Page = routeImport.default;
37
39
  const stream = await renderToReadableStream(
38
40
  <html lang="en">
@@ -42,7 +44,7 @@ const renderPage = async (filePath, url, params) => {
42
44
  __html: JSON.stringify(
43
45
  {
44
46
  "imports": {
45
- ...deps,
47
+ ...imports,
46
48
  "react-dom/client": "https://esm.sh/[email protected]/client?dev",
47
49
  "react/jsx-dev-runtime": "https://esm.sh/[email protected]/jsx-dev-runtime?dev",
48
50
  "@/atom.js": "/assets/js/src/atom.js",
@@ -126,7 +128,7 @@ export default {
126
128
  });
127
129
  }
128
130
  if (url.pathname.includes("/")) {
129
- return renderPage("./routes/index/page.jsx", url, {});
131
+ return renderPage(process.cwd() + "/routes/index/page.jsx", url, {});
130
132
  }
131
133
  return new Response(`Not Found`, {
132
134
  headers: { 'Content-Type': 'text/html' },
jsxPlugin.js → packages/muffinjs/jsxPlugin.js RENAMED
File without changes
packages/muffinjs/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "muffinjs",
3
+ "version": "0.1.0",
4
+ "module": "index.js",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "bun --hot index.js",
8
+ "start": "bun index.js"
9
+ },
10
+ "devDependencies": {
11
+ "bun-types": "^0.5.0"
12
+ },
13
+ "dependencies": {
14
+ "autoprefixer": "^10.4.14",
15
+ "postcss": "^8.4.21",
16
+ "postcss-custom-media": "^9.1.2",
17
+ "postcss-nesting": "^11.2.1",
18
+ "postcss-normalize": "^10.0.1"
19
+ },
20
+ "bin": {
21
+ "muffin": "./bin/muffin"
22
+ }
23
+ }
router.js → packages/muffinjs/router.js RENAMED
@@ -1,10 +1,11 @@
1
+ // import { signal, useSignal } from "@preact/signals-react";
1
- import { atom, useAtom } from "@/atom.js";
2
+ import { atom, useAtom } from "./atom.js";
2
3
 
3
4
  export const routerAtom = atom({
4
5
  pathname: "/",
5
6
  query: {},
6
7
  params: {},
7
- })
8
+ });
8
9
 
9
10
  export const useRouter = () => useAtom(routerAtom);
10
11