Skip to content

Commit bb1d25c

Browse files
authored
feat: update the route file format to allow for using route factories (#97)
* refactor: update the routes folder format for the init command * feat: add back the example route to the content-api routes
1 parent 77ff79f commit bb1d25c

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

.changeset/cyan-beds-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@strapi/sdk-plugin': minor
3+
---
4+
5+
refactor: update the routes folder format for the init command

src/cli/commands/plugin/init/files/server.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
130130
`,
131131
},
132132
{
133-
name: 'server/src/routes/content-api.ts',
133+
name: 'server/src/routes/content-api/index.ts',
134134
contents: outdent`
135-
export default [
135+
export default () => ({
136+
type: 'content-api',
137+
routes: [
136138
{
137139
method: 'GET',
138140
path: '/',
@@ -142,19 +144,28 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [
142144
policies: [],
143145
},
144146
},
145-
];
147+
],
148+
});
149+
`,
150+
},
151+
{
152+
name: 'server/src/routes/admin/index.ts',
153+
contents: outdent`
154+
export default () => ({
155+
type: 'admin',
156+
routes: [],
157+
});
146158
`,
147159
},
148160
{
149161
name: 'server/src/routes/index.ts',
150162
contents: outdent`
151163
import contentAPIRoutes from './content-api';
164+
import adminAPIRoutes from './admin';
152165
153166
const routes = {
154-
'content-api': {
155-
type: 'content-api',
156-
routes: contentAPIRoutes,
157-
},
167+
'content-api': contentAPIRoutes,
168+
admin: adminAPIRoutes,
158169
};
159170
160171
export default routes;
@@ -307,9 +318,11 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [
307318
`,
308319
},
309320
{
310-
name: 'server/src/routes/content-api.js',
321+
name: 'server/src/routes/content-api/index.js',
311322
contents: outdent`
312-
export default [
323+
export default () => ({
324+
type: 'content-api',
325+
routes: [
313326
{
314327
method: 'GET',
315328
path: '/',
@@ -319,19 +332,28 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [
319332
policies: [],
320333
},
321334
},
322-
];
335+
],
336+
});
337+
`,
338+
},
339+
{
340+
name: 'server/src/routes/admin/index.js',
341+
contents: outdent`
342+
export default () => ({
343+
type: 'admin',
344+
routes: [],
345+
});
323346
`,
324347
},
325348
{
326349
name: 'server/src/routes/index.js',
327350
contents: outdent`
328351
import contentAPIRoutes from './content-api';
352+
import adminAPIRoutes from './admin';
329353
330354
const routes = {
331-
'content-api': {
332-
type: 'content-api',
333-
routes: contentAPIRoutes,
334-
},
355+
'content-api': contentAPIRoutes,
356+
admin: adminAPIRoutes,
335357
};
336358
337359
export default routes;

0 commit comments

Comments
 (0)