create-evikit 2.9.1 → 2.10.1
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.html +1 -1
- package/index.js +1 -1
- package/package.json +2 -2
- package/src/prerender.js +14 -0
- package/src/routes/api/server.js +1 -1
- package/src/routes/api/todo/server.js +21 -21
- package/src/app.js +0 -26
package/index.html
CHANGED
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { readFile } from "node:fs/promises";
|
|
|
4
4
|
import swaggerUi from "swagger-ui-express";
|
|
5
5
|
|
|
6
6
|
import { api } from "./src/api.js";
|
|
7
|
-
import { prerender } from "./src/
|
|
7
|
+
import { prerender } from "./src/prerender.js";
|
|
8
8
|
|
|
9
9
|
const app = express();
|
|
10
10
|
app.use("/static", express.static("./static"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-evikit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": "bin/create-evikit.js",
|
|
6
6
|
"scripts": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"accept-language": "^3.0.20",
|
|
38
38
|
"classnames": "^2.5.1",
|
|
39
39
|
"cross-env": "^10.1.0",
|
|
40
|
-
"evikit": "^2.
|
|
40
|
+
"evikit": "^2.10.0",
|
|
41
41
|
"express": "^5.2.1",
|
|
42
42
|
"file-type": "^22.1.1",
|
|
43
43
|
"hoofd": "^1.7.3",
|
package/src/prerender.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { route, ssr } from "evikit";
|
|
2
|
+
|
|
3
|
+
import { acceptLanguages } from "./lib/index.js";
|
|
4
|
+
import { ErrorPage } from "./routes/error.js";
|
|
5
|
+
import { HomePage } from "./routes/page.js";
|
|
6
|
+
import { TodoPage } from "./routes/todo/page.js";
|
|
7
|
+
|
|
8
|
+
acceptLanguages();
|
|
9
|
+
|
|
10
|
+
export const prerender = ssr(
|
|
11
|
+
{ ErrorPage },
|
|
12
|
+
route("/", HomePage),
|
|
13
|
+
route("/todo", TodoPage),
|
|
14
|
+
);
|
package/src/routes/api/server.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { endpoint, json, redirect } from "evikit/server";
|
|
2
|
-
|
|
3
|
-
import { db } from "../../../lib/db/index.js";
|
|
4
|
-
import { TodoGet, TodoPost } from "./types.js";
|
|
5
|
-
|
|
6
|
-
export const TodoServer = {
|
|
7
|
-
get: endpoint(TodoGet, async () => json({ Todo: db.Todo.select() })),
|
|
8
|
-
|
|
9
|
-
post: endpoint(TodoPost, async ({ input }) => {
|
|
10
|
-
const [todo] = db.Todo.select({ where: { text: input.text } });
|
|
11
|
-
if (todo) {
|
|
12
|
-
db.Todo.update({
|
|
13
|
-
set: { doneAt: todo.doneAt ? undefined : Date.now() },
|
|
14
|
-
where: { text: todo.text },
|
|
15
|
-
});
|
|
16
|
-
} else {
|
|
17
|
-
db.Todo.upsert({ createdAt: Date.now(), text: input.text });
|
|
18
|
-
}
|
|
19
|
-
return redirect("/todo", 302);
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
1
|
+
import { endpoint, json, redirect } from "evikit/server";
|
|
2
|
+
|
|
3
|
+
import { db } from "../../../lib/db/index.js";
|
|
4
|
+
import { TodoGet, TodoPost } from "./types.js";
|
|
5
|
+
|
|
6
|
+
export const TodoServer = {
|
|
7
|
+
get: endpoint(TodoGet, async () => json({ Todo: db.Todo.select() })),
|
|
8
|
+
|
|
9
|
+
post: endpoint(TodoPost, async ({ input }) => {
|
|
10
|
+
const [todo] = db.Todo.select({ where: { text: input.text } });
|
|
11
|
+
if (todo) {
|
|
12
|
+
db.Todo.update({
|
|
13
|
+
set: { doneAt: todo.doneAt ? undefined : Date.now() },
|
|
14
|
+
where: { text: todo.text },
|
|
15
|
+
});
|
|
16
|
+
} else {
|
|
17
|
+
db.Todo.upsert({ createdAt: Date.now(), text: input.text });
|
|
18
|
+
}
|
|
19
|
+
return redirect("/todo", 302);
|
|
20
|
+
}),
|
|
21
|
+
};
|
package/src/app.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { hydrate, Router, ssr } from "evikit";
|
|
2
|
-
import { h } from "preact";
|
|
3
|
-
import { Route } from "preact-iso";
|
|
4
|
-
|
|
5
|
-
import { acceptLanguages } from "./lib/index.js";
|
|
6
|
-
import { ErrorPage } from "./routes/error.js";
|
|
7
|
-
import { HomePage } from "./routes/page.js";
|
|
8
|
-
import { TodoPage } from "./routes/todo/page.js";
|
|
9
|
-
|
|
10
|
-
acceptLanguages();
|
|
11
|
-
|
|
12
|
-
/** @param {import("evikit").SsrProps} props */
|
|
13
|
-
export const prerender = (props) => ssr(App, props);
|
|
14
|
-
|
|
15
|
-
/** @type {import("evikit").SsrApp} */
|
|
16
|
-
export function App(props) {
|
|
17
|
-
return h(
|
|
18
|
-
Router,
|
|
19
|
-
props,
|
|
20
|
-
h(Route, { component: HomePage, path: "/" }),
|
|
21
|
-
h(Route, { component: TodoPage, path: "/todo" }),
|
|
22
|
-
h(Route, { component: ErrorPage, default: true }),
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
hydrate(App, "#app");
|