Skip to content

Commit d35da30

Browse files
committed
doing changes for custom options in middlewares
1 parent 721137d commit d35da30

File tree

13 files changed

+128
-120
lines changed

13 files changed

+128
-120
lines changed

build/tsconfig.types.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"declarationMap": true, /* go to js file when using IDE functions like. "Go to Definition" in VSCode */
55
"emitDeclarationOnly": true,
66
"allowJs": true,
7-
"incremental": true,
7+
"incremental": false,
88
"outDir": "./dist/src",
99
"preserveSymlinks": true,
1010
"target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */

libs/express-adapter/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
},
2121
"scripts": {
2222
"clear": "rimraf ./dist",
23-
"build:types": "tsc --project tsconfig.types.json",
24-
"build:cjs:esm": "tsup ./src --out-dir ./dist/src --format cjs,esm --silent --no-splitting",
25-
"build": "pnpm run clear && pnpm run build:cjs:esm && pnpm run build:types",
26-
"build:types:watch": "tsc --project tsconfig.types.json --watch --preserveWatchOutput",
27-
"build:cjs:esm:watch": "tsup ./src --out-dir ./dist/src --format cjs,esm --watch --silent --no-splitting",
28-
"build:watch": "pnpm run build:cjs:esm:watch & pnpm run build:types:watch"
23+
"build": "tsup ./src --out-dir ./dist/src --format cjs,esm --dts --tsconfig tsconfig.types.json --clean --silent --no-splitting",
24+
"build:watch": "tsup ./src --out-dir ./dist/src --format cjs,esm --dts --tsconfig tsconfig.types.json --clean --watch --silent --no-splitting"
2925
},
3026
"type": "module",
3127
"repository": {

libs/express-adapter/src/router.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ export const routerAdapter = serverRouterAdapter({
1717
parseHandlers(_, initializedServer: Express, path, handlers: ParseHandlersServer<RequestHandler[]>, __, handler404) {
1818
// This will initialize the server routes.
1919
initializedServer.all(path, (req: Request, res: Response) => {
20-
let currentMiddlewareIndex = 0;
20+
let currentMiddlewareIndex = -1;
2121

2222
const runMiddlewares = (methodType: MethodTypes | 'all', req: Request, res: Response) => {
2323
const next = () => {
24-
if (handlers.get(methodType)?.options?.[currentMiddlewareIndex])
24+
currentMiddlewareIndex = Number(currentMiddlewareIndex) + 1;
25+
if (handlers.get(methodType)?.options?.[currentMiddlewareIndex]) {
2526
handlers.get(methodType)?.options?.[currentMiddlewareIndex]?.(req, res, next);
26-
else handlers.get(methodType)?.handler({ req, res });
27-
currentMiddlewareIndex++;
27+
} else {
28+
handlers.get(methodType)?.handler({ req, res });
29+
}
2830
};
2931

3032
next();

libs/express-adapter/tsconfig.types.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"compilerOptions": {
44
"declaration": true /* Generate d.ts files */,
55
"esModuleInterop": true,
6+
"emitDeclarationOnly": false,
67
"allowSyntheticDefaultImports": true,
78
"rootDir": "./src",
89
"outDir": "./dist/src",

libs/vercel-adapter/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
},
2121
"scripts": {
2222
"clear": "rimraf ./dist",
23-
"build:types": "tsc --project tsconfig.types.json",
24-
"build:cjs:esm": "tsup ./src --out-dir ./dist/src --format cjs,esm --silent --no-splitting",
25-
"build": "pnpm run clear && pnpm run build:cjs:esm && pnpm run build:types",
26-
"build:types:watch": "tsc --project tsconfig.types.json --watch --preserveWatchOutput",
27-
"build:cjs:esm:watch": "tsup ./src --out-dir ./dist/src --format cjs,esm --watch --silent --no-splitting",
28-
"build:watch": "pnpm run build:cjs:esm:watch & pnpm run build:types:watch"
23+
"build": "tsup ./src --out-dir ./dist/src --format cjs,esm --dts --tsconfig tsconfig.types.json --clean --silent --no-splitting",
24+
"build:watch": "tsup ./src --out-dir ./dist/src --format cjs,esm --dts --tsconfig tsconfig.types.json --clean --watch --silent --no-splitting"
2925
},
3026
"type": "module",
3127
"repository": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"rimraf": "^6.0.1",
7676
"tsup": "^8.2.4",
7777
"tsx": "^4.19.3",
78-
"turbo": "^2.4.2",
78+
"turbo": "^2.4.4",
7979
"typescript": "^5.5.4",
8080
"typescript-eslint": "^8.24.1"
8181
}

packages/core/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@
3030
"scripts": {
3131
"copy:templates": "copyfiles -u 1 \"templates/**/*\" ../../bin/templates/app",
3232
"clear": "rimraf ./dist",
33-
"build:types": "tsc --project tsconfig.types.json",
34-
"build:cjs:esm": "tsup ./src --out-dir ./dist/src --format cjs,esm --silent --no-splitting",
35-
"build": "pnpm run clear && pnpm run build:cjs:esm && pnpm run build:types",
36-
"build:types:watch": "tsc --project tsconfig.types.json --watch --preserveWatchOutput",
37-
"build:cjs:esm:watch": "tsup ./src --out-dir ./dist/src --format cjs,esm --watch --silent --no-splitting",
38-
"build:watch": "pnpm run build:cjs:esm:watch & pnpm run build:types:watch"
33+
"build": "tsup ./src --out-dir ./dist/src --format cjs,esm --dts --tsconfig tsconfig.types.json --clean --silent --no-splitting",
34+
"build:watch": "tsup ./src --out-dir ./dist/src --format cjs,esm --dts --tsconfig tsconfig.types.json --watch --silent --no-splitting"
3935
},
4036
"type": "module",
4137
"author": "Nicolas Leal",

packages/server/__tests__/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
"@palmares/node-std": "workspace:*",
2222
"@palmares/server": "workspace:*",
2323
"@palmares/tests": "workspace:*",
24+
"cors": "^2.8.5",
2425
"drizzle-kit": "^0.30.5",
2526
"drizzle-orm": "^0.39.3"
2627
},
2728
"devDependencies": {
2829
"@types/better-sqlite3": "^7.6.11",
29-
"better-sqlite3": "^11.8.1",
3030
"@types/cors": "^2.8.17",
3131
"@types/supertest": "^6.0.2",
32+
"better-sqlite3": "^11.8.1",
3233
"eslint": "^9.9.1",
3334
"supertest": "^7.0.0",
3435
"ts-jest-mock-import-meta": "^1.2.0",

packages/server/__tests__/src/core/index.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
import { domain } from '@palmares/core';
2-
import { Response, path, serverDomainModifier } from '@palmares/server';
2+
import { Response, middleware, path, serverDomainModifier } from '@palmares/server';
33
import { testDomainModifier } from '@palmares/tests';
4+
import cors from 'cors';
45
import { dirname } from 'path';
56
import { fileURLToPath } from 'url';
67

78
const __filename = fileURLToPath(import.meta.url);
89
const __dirname = dirname(__filename);
9-
const route = path('/test').get(() => {
10-
console.log('hello');
11-
return Response.json({ message: 'hello' }, { status: 200 });
10+
11+
const testMiddleware = middleware({
12+
options: {
13+
customOptions: [cors()]
14+
}
1215
});
16+
const route = path('/test')
17+
.middlewares([testMiddleware])
18+
.get(
19+
(req) => {
20+
console.log(req.serverData().req.params);
21+
return Response.json({ message: 'hello' }, { status: 200 });
22+
},
23+
{
24+
customOptions: [cors()]
25+
}
26+
);
1327

1428
export default domain('testingExpressServer', __dirname, {
1529
modifiers: [serverDomainModifier, testDomainModifier] as const,

packages/server/__tests__/src/core/test.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ExpressServerAdapter from '@palmares/express-adapter';
1+
import { ExpressServerAdapter } from '@palmares/express-adapter';
22
import { getAdapterServer, loadServerWhenTesting } from '@palmares/server';
33
import { beforeAll, describe } from '@palmares/tests';
44
import supertest from 'supertest';

0 commit comments

Comments
 (0)