princejs 1.7.3 → 1.7.6
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 +26 -8
- package/dist/create.js +1 -1
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -105,8 +105,9 @@ import { cron, openapi } from "princejs/scheduler";
|
|
|
105
105
|
import { prince } from "princejs";
|
|
106
106
|
import { cors, logger, rateLimit } from "princejs/middleware";
|
|
107
107
|
import { validate } from "princejs/validation";
|
|
108
|
-
import { cache,
|
|
108
|
+
import { cache, upload } from "princejs/helpers";
|
|
109
109
|
import { cron } from "princejs/scheduler";
|
|
110
|
+
import { Html, Head, Body, H1, P, render } from "princejs/jsx"
|
|
110
111
|
import { z } from "zod";
|
|
111
112
|
|
|
112
113
|
const app = prince(true);
|
|
@@ -117,23 +118,40 @@ app.use(rateLimit({ max: 100, window: 60 }));
|
|
|
117
118
|
|
|
118
119
|
app.use(validate(z.object({ name: z.string() })));
|
|
119
120
|
|
|
121
|
+
const Page = () => (
|
|
122
|
+
Html({
|
|
123
|
+
children: [
|
|
124
|
+
Head({
|
|
125
|
+
children: [
|
|
126
|
+
"Test Page"
|
|
127
|
+
]
|
|
128
|
+
}),
|
|
129
|
+
Body({
|
|
130
|
+
children: [
|
|
131
|
+
H1({
|
|
132
|
+
children: "Hello World"
|
|
133
|
+
}),
|
|
134
|
+
P({
|
|
135
|
+
children: "This is a test"
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
})
|
|
139
|
+
]
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
|
|
120
143
|
app.get("/", () => ({ message: "Welcome to PrinceJS" }));
|
|
121
144
|
|
|
122
145
|
app.get("/users/:id", (req) => ({ id: req.params.id }));
|
|
123
146
|
|
|
124
|
-
app.get("/
|
|
147
|
+
app.get("/jsx", () => render(Page()));
|
|
125
148
|
|
|
126
|
-
app.
|
|
149
|
+
app.get("/data", cache(60)(() => ({ time: Date.now() })));
|
|
127
150
|
|
|
128
151
|
app.post("/upload", upload(), (req) => ({ files: Object.keys(req.files || {}) }));
|
|
129
152
|
|
|
130
153
|
cron("*/1 * * * *", () => console.log("PrinceJS heartbeat"));
|
|
131
154
|
|
|
132
|
-
app.ws("/chat", {
|
|
133
|
-
open: (ws) => ws.send("Welcome!"),
|
|
134
|
-
message: (ws, msg) => ws.send(`Echo: ${msg}`)
|
|
135
|
-
});
|
|
136
|
-
|
|
137
155
|
app.listen(3000);
|
|
138
156
|
```
|
|
139
157
|
|
package/dist/create.js
CHANGED