diesel-core 1.0.2 → 1.0.4

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 (2) hide show
  1. package/README.md +10 -13
  2. package/package.json +1 -6
package/README.md CHANGED
@@ -64,10 +64,10 @@ app.options()
64
64
  ### Diesel supports cors out of the box
65
65
 
66
66
  ``` javascript
67
- app.cors({
67
+ app.use(cors{
68
68
  origin: ['http://localhost:5173','*'],
69
- methods: 'GET,POST,PUT,DELETE',
70
- allowedHeaders: 'Content-Type,Authorization'
69
+ methods: ['GET','POST','PUT','DELETE'],
70
+ allowedHeaders: ['Content-Type','Authorization']
71
71
  })
72
72
  ```
73
73
 
@@ -87,7 +87,7 @@ import jwt from 'jsonwebtoken';
87
87
  const app = new Diesel();
88
88
 
89
89
  async function authJwt (ctx:ContextType, server?:Server): Promise<void | Response> {
90
- const token = await ctx.getCookie("accessToken"); // Retrieve the JWT token from cookies
90
+ const token = await ctx.cookies?.accessToken // Retrieve the JWT token from cookies
91
91
  if (!token) {
92
92
  return ctx.json({ message: "Authentication token missing" },401);
93
93
  }
@@ -95,10 +95,7 @@ async function authJwt (ctx:ContextType, server?:Server): Promise<void | Respons
95
95
  // Verify the JWT token using a secret key
96
96
  const user = jwt.verify(token, secret); // Replace with your JWT secret
97
97
  // Set the user data in context
98
- ctx.setUser(user);
99
-
100
- // Proceed to the next middleware/route handler
101
- return ctx.next();
98
+ ctx.set('user',user);
102
99
  } catch (error) {
103
100
  return ctx.json({ message: "Invalid token" },403);
104
101
  }
@@ -119,7 +116,7 @@ app.get("/api/user/register", async (ctx:ContextType) => {
119
116
  // Example protected route (requires auth)
120
117
  app.get("/api/user/profile", async (ctx:ContextType) => {
121
118
  // This route is protected, so the auth middleware will run before this handler
122
- const user = ctx.getUser()
119
+ const user = ctx.get.user
123
120
  return ctx.json({
124
121
  msg: "You are authenticated!" ,
125
122
  user
@@ -222,7 +219,7 @@ app.addHooks('onSend',async (ctx, result) => {
222
219
  async function authJwt (ctx:ContextType, server?:Server): Promise<void | Response> {
223
220
 
224
221
  try {
225
- const token = ctx?.getCookie("accessToken");
222
+ const token = ctx.cookies?.accessToken
226
223
  if (!token) {
227
224
  return ctx.json({ message: "Authentication token missing" },401);
228
225
  }
@@ -294,13 +291,13 @@ app.get("/redirect",(ctx:ContextType) => {
294
291
  **You can use set ***Multiparams***** , ***like this***
295
292
 
296
293
  ```javascript
297
- app.get("/product/:productId/:productName)
294
+ app.get("/product/:productId/:productName")
298
295
  ```
299
296
 
300
297
  ```javascript
301
298
  app.get("/hello/:id/",(ctx:ContextType) => {
302
- const id = ctx.getParams("id")
303
- const query = ctx.getQuery() // you can pass query name also , you wanna get
299
+ const id = ctx.params.id
300
+ const query = ctx.query // you can pass query name also , you wanna get
304
301
  return ctx.json({ msg: "Hello", id });
305
302
  })
306
303
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diesel-core",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -8,11 +8,6 @@
8
8
  "./dist"
9
9
  ],
10
10
  "exports": {
11
- ".": {
12
- "types": "./dist/main.d.ts",
13
- "import": "./dist/main.js",
14
- "require": "./dist/main.js"
15
- },
16
11
  "./cors": {
17
12
  "types": "./dist/middlewares/cors/cors.d.ts",
18
13
  "import": "./src/middlewares/cors/cors.js",