diesel-core 1.6.4 → 1.6.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.
Files changed (3) hide show
  1. package/README.md +37 -23
  2. package/index.js +1 -1
  3. package/package.json +6 -2
package/README.md CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  # DieselJS
4
4
 
5
- **made only for bun***
6
5
 
7
6
  **Diesel** is a simple and lightweight HTTP server library for Bun.js that provides you with complete control over your API routes and middleware. It is designed to be intuitive and efficient, allowing you to quickly set up a server, define routes, and optimize important paths for faster response times.
8
7
 
9
- With built-in support for TypeScript, DieselJS ensures type safety and improved developer experience, making it easier to catch errors during development. Whether you are building a small application or a large API, DieselJS helps you manage your routes and middleware seamlessly.
8
+ **Now Supports Node.js & Cloduflare adaptors**
10
9
 
11
10
 
12
11
  ## Installation
@@ -40,30 +39,50 @@ app.listen(port, () => {
40
39
  **In Diesel there are almost all http methods that you can use**
41
40
 
42
41
  ```javascript
43
- app.get()
42
+ app.get() app.post() app.put()
43
+ app.patch() app.delete() app.any()
44
+ app.head() app.options() , app.onMethod(method,path,handler)
45
+ ```
46
+ # Cloudflare workers
44
47
 
45
- app.post()
48
+ ### now you can use diesel.js for cloudflare workers apis
46
49
 
47
- app.put()
50
+ ```ts
51
+ import {Diesel} from "diesel-core"
52
+ const app = new Diesel({
53
+ platform: 'cf',
54
+ onError: true
55
+ })
56
+ .get("/", (ctx) => ctx.text("Welcome to Diesel.js on Cloudflare Workers!"));
48
57
 
49
- app.patch()
58
+ export default {
59
+ fetch: app.fetch()
60
+ }
50
61
 
51
- app.delete()
62
+ ```
63
+ **Note make sure to call fetch(), it gives you real fetch handler**
52
64
 
53
- app.any() // used for all http methods such as GET,POST,PUT..
65
+ # Node.js adaptor
66
+ ### Now you can use Diesel.js for Node.js
54
67
 
55
- app.head()
68
+ ```ts
69
+ import {Diesel} from 'diesel-core'
70
+ import {serve} from 'diesel-core/node'
56
71
 
57
- app.options()
72
+ const app = new Diesel({})
73
+ .get("/", (c) => c.text(`hello from node diesel/`))
58
74
 
75
+ serve({
76
+ fetch: app.fetch(),
77
+ port: 3000
78
+ })
59
79
  ```
60
80
 
61
-
62
81
  # CORS
63
82
 
64
83
  ### Diesel supports cors out of the box
65
84
 
66
- ``` javascript
85
+ ``` ts
67
86
  app.use(cors{
68
87
  origin: ['http://localhost:5173','*'],
69
88
  methods: ['GET','POST','PUT','DELETE'],
@@ -163,9 +182,9 @@ DieselJS allows you to enhance your request handling by utilizing hooks at vario
163
182
 
164
183
  1. **onRequest**: Triggered when a request is received.
165
184
  2. **preHandler**: Invoked just before the request handler executes.
166
- 3. **postHandler**: Executed after the request handler completes but before sending the response.
167
- 4. **onSend**: Called just before the response is sent to the client.
168
- 5. **onError** : Executes if any error occurs
185
+ <!-- 3. **postHandler**: Executed after the request handler completes but before sending the response. -->
186
+ 3. **onSend**: Called just before the response is sent to the client.
187
+ 4. **onError** : Executes if any error occurs
169
188
 
170
189
  ### How to Define Hooks
171
190
 
@@ -197,11 +216,6 @@ app.addHooks("preHandler",(ctx:ContextType) =>{
197
216
  }
198
217
  })
199
218
 
200
- // Define a postHandler hook
201
- app.addHooks('postHandler', async (ctx:ContextType) => {
202
- console.log(`Response sent for: ${ctx.req.url}`);
203
- });
204
-
205
219
  // Define an onSend hook
206
220
  app.addHooks('onSend',async (ctx, result) => {
207
221
  console.log(`Sending response with status: ${result.status}`);
@@ -216,7 +230,7 @@ app.addHooks('onSend',async (ctx, result) => {
216
230
  **just dont return , if evrything goes right**
217
231
 
218
232
  ```javascript
219
- async function authJwt (ctx:ContextType, server?:Server): Promise<void | Response> {
233
+ async function authJwt (ctx:ContextType): Promise<void | Response> {
220
234
 
221
235
  try {
222
236
  const token = ctx.cookies?.accessToken
@@ -234,12 +248,12 @@ async function authJwt (ctx:ContextType, server?:Server): Promise<void | Respons
234
248
  // this is a global middleware
235
249
  app.use(authJwt)
236
250
  OR
237
- app.use([authJwt,middleware2 , ...])
251
+ app.use(authJwt,middleware2 , ...)
238
252
 
239
253
  // path middleware example
240
254
  app.use("/user",authJWT)
241
255
  OR
242
- app.use(["/user","/home"],[authJWT,middleware2])
256
+ // app.use(["/user","/home"],[authJWT,middleware2])
243
257
  //means /user and /home has two middlewares
244
258
 
245
259
 
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import Diesel from './dist/main'
1
+ import Diesel from './dist/main.js'
2
2
 
3
3
 
4
4
  export {Diesel}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diesel-core",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -69,6 +69,11 @@
69
69
  "types": "./dist/http-exception.d.ts",
70
70
  "import": "./dist/http-exception.js",
71
71
  "require": "./dist/http-exception.js"
72
+ },
73
+ "./node":{
74
+ "types": "./dist/adaptor/node/main.d.ts",
75
+ "import":"./dist/adaptor/node/main.js",
76
+ "require":"./dist/adaptor/node/main.js"
72
77
  }
73
78
  },
74
79
  "scripts": {
@@ -105,7 +110,6 @@
105
110
  "dependencies": {
106
111
  "@types/ejs": "^3.1.5",
107
112
  "@types/uuid": "^10.0.0",
108
- "ejs": "^3.1.10",
109
113
  "find-my-way": "^9.3.0",
110
114
  "uuid": "^11.1.0"
111
115
  }