silgi 0.36.7 → 0.36.9
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/dist/cli/build.mjs
CHANGED
|
@@ -256,6 +256,36 @@ async function nextJS(silgi, skip = false) {
|
|
|
256
256
|
write: true,
|
|
257
257
|
getContents: () => template.join("\n")
|
|
258
258
|
});
|
|
259
|
+
const routerPrefixs = [];
|
|
260
|
+
for (const route in silgi.services) {
|
|
261
|
+
const routeParts = route.split("/").filter(Boolean);
|
|
262
|
+
if (routeParts.length > 0) {
|
|
263
|
+
const prefix = `/${routeParts[0]}`;
|
|
264
|
+
if (!routerPrefixs.includes(prefix)) {
|
|
265
|
+
routerPrefixs.push(prefix);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
for (const prefix of routerPrefixs) {
|
|
270
|
+
const file = `src/app${prefix}/[...all]/route.ts`;
|
|
271
|
+
const fileExists = existsSync(file);
|
|
272
|
+
if (!fileExists) {
|
|
273
|
+
const serverDirName = `@/${silgi.options.silgi.serverDir.split("/src/")[1]}/core`;
|
|
274
|
+
const template2 = `import { toNextJsHandler } from 'silgi/runtime/internal/next'
|
|
275
|
+
import { buildSilgi } from '${serverDirName}'
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
const silgi = await buildSilgi()
|
|
279
|
+
|
|
280
|
+
export const { GET, POST, PUT, DELETE, PATCH } = toNextJsHandler()`;
|
|
281
|
+
addTemplate({
|
|
282
|
+
filename: file,
|
|
283
|
+
where: ".silgi",
|
|
284
|
+
write: true,
|
|
285
|
+
getContents: () => template2
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
259
289
|
}
|
|
260
290
|
|
|
261
291
|
async function nitroFramework(silgi, skip = false) {
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { Silgi } from 'silgi/types';
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
2
|
+
export declare function toNextJsHandler(silgiContext?: Silgi): {
|
|
3
|
+
GET: (request: Request) => Promise<Response>;
|
|
4
|
+
POST: (request: Request) => Promise<Response>;
|
|
5
|
+
PUT: (request: Request) => Promise<Response>;
|
|
6
|
+
DELETE: (request: Request) => Promise<Response>;
|
|
7
|
+
PATCH: (request: Request) => Promise<Response>;
|
|
8
|
+
};
|
|
9
|
+
export default toNextJsHandler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createError, getUrlPrefix, isError, silgiFetch, useSilgi } from "silgi";
|
|
2
|
-
export function
|
|
3
|
-
|
|
2
|
+
export function toNextJsHandler(silgiContext = useSilgi()) {
|
|
3
|
+
const handler = async (request) => {
|
|
4
4
|
if (!silgiContext) {
|
|
5
5
|
throw new Error("Silgi context is not defined");
|
|
6
6
|
}
|
|
@@ -53,5 +53,12 @@ export function addNextApp(silgiContext = useSilgi()) {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
+
return {
|
|
57
|
+
GET: handler,
|
|
58
|
+
POST: handler,
|
|
59
|
+
PUT: handler,
|
|
60
|
+
DELETE: handler,
|
|
61
|
+
PATCH: handler
|
|
62
|
+
};
|
|
56
63
|
}
|
|
57
|
-
export default
|
|
64
|
+
export default toNextJsHandler;
|