@flow-os/server 0.0.51-dev.1772057564 → 0.0.52
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/package.json +1 -1
- package/src/plugin.ts +2 -6
- package/src/router.ts +11 -7
package/package.json
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -58,8 +58,6 @@ export type FlowServerOptions = {
|
|
|
58
58
|
routesDir?: string;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
type ConnectStack = Array<{ route: string; handle: (req: NodeReq, res: NodeRes, next: () => void) => void }>;
|
|
62
|
-
|
|
63
61
|
export function flowServer(options?: FlowServerOptions): Plugin {
|
|
64
62
|
return {
|
|
65
63
|
name: 'flow-os:server',
|
|
@@ -72,10 +70,8 @@ export function flowServer(options?: FlowServerOptions): Plugin {
|
|
|
72
70
|
server.ssrLoadModule(pathToFileURL(filePath).href) as Promise<{ default: FlowHandler }>;
|
|
73
71
|
const { dispatch, matches } = await createFlowServer(routesDir, loadHandler);
|
|
74
72
|
const middleware = flowServerMiddleware(dispatch, matches);
|
|
75
|
-
(server.middlewares as unknown as { stack:
|
|
76
|
-
|
|
77
|
-
handle: middleware,
|
|
78
|
-
});
|
|
73
|
+
const stack = (server.middlewares as unknown as { stack: Array<{ route: string; handle: (req: NodeReq, res: NodeRes, next: () => void) => void }> }).stack;
|
|
74
|
+
stack.unshift({ route: '', handle: middleware });
|
|
79
75
|
},
|
|
80
76
|
};
|
|
81
77
|
}
|
package/src/router.ts
CHANGED
|
@@ -43,10 +43,10 @@ function segmentsToPattern(segments: string[]): string {
|
|
|
43
43
|
return '/' + parts.join('/');
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
/**
|
|
47
|
-
const
|
|
46
|
+
/** Metodi per file senza suffisso (.get, .post, ecc.): GET e POST (visita browser + fetch) */
|
|
47
|
+
const DEFAULT_METHODS = ['GET', 'POST'] as const;
|
|
48
48
|
|
|
49
|
-
function parseRoutePath(relativePath: string): { path: string;
|
|
49
|
+
function parseRoutePath(relativePath: string): { path: string; methods: readonly string[] } | null {
|
|
50
50
|
const lower = relativePath.toLowerCase();
|
|
51
51
|
const ext = lower.endsWith('.tsx') ? '.tsx' : '.ts';
|
|
52
52
|
for (const suffix of METHOD_SUFFIXES) {
|
|
@@ -56,16 +56,16 @@ function parseRoutePath(relativePath: string): { path: string; method: string }
|
|
|
56
56
|
const path = segmentsToPattern(segments);
|
|
57
57
|
const pathNorm = path === '/index' ? '/' : path;
|
|
58
58
|
const method = suffix.slice(1).toUpperCase();
|
|
59
|
-
return { path: pathNorm, method };
|
|
59
|
+
return { path: pathNorm, methods: [method] };
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
// File senza suffisso (api.ts, users.ts): POST
|
|
62
|
+
// File senza suffisso (api.ts, users.ts): GET e POST
|
|
63
63
|
if (lower.endsWith(ext)) {
|
|
64
64
|
const withoutExt = relativePath.slice(0, -ext.length);
|
|
65
65
|
const segments = withoutExt.split(/[/\\]/).filter(Boolean);
|
|
66
66
|
const path = segmentsToPattern(segments);
|
|
67
67
|
const pathNorm = path === '/index' ? '/' : path;
|
|
68
|
-
return { path: pathNorm,
|
|
68
|
+
return { path: pathNorm, methods: [...DEFAULT_METHODS] };
|
|
69
69
|
}
|
|
70
70
|
return null;
|
|
71
71
|
}
|
|
@@ -85,7 +85,11 @@ export async function walkRoutes(dir: string, base = ''): Promise<RouteMeta[]> {
|
|
|
85
85
|
routes.push(...(await walkRoutes(join(dir, name), rel)));
|
|
86
86
|
} else if (e.isFile() && (name.endsWith('.ts') || name.endsWith('.tsx'))) {
|
|
87
87
|
const parsed = parseRoutePath(rel);
|
|
88
|
-
if (parsed)
|
|
88
|
+
if (parsed) {
|
|
89
|
+
for (const method of parsed.methods) {
|
|
90
|
+
routes.push({ path: parsed.path, method, filePath: join(dir, name) });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
return routes;
|