Skip to content

Commit 0354cdb

Browse files
committed
refactor: update the routes folder format for the init command
1 parent 77ff79f commit 0354cdb

File tree

2 files changed

+39
-32
lines changed

2 files changed

+39
-32
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: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,32 @@ 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 [
136-
{
137-
method: 'GET',
138-
path: '/',
139-
// name of the controller file & the method.
140-
handler: 'controller.index',
141-
config: {
142-
policies: [],
143-
},
144-
},
145-
];
135+
export default () => ({
136+
type: 'content-api',
137+
routes: [],
138+
});
139+
`,
140+
},
141+
{
142+
name: 'server/src/routes/admin/index.ts',
143+
contents: outdent`
144+
export default () => ({
145+
type: 'admin',
146+
routes: [],
147+
});
146148
`,
147149
},
148150
{
149151
name: 'server/src/routes/index.ts',
150152
contents: outdent`
151153
import contentAPIRoutes from './content-api';
154+
import adminAPIRoutes from './admin';
152155
153156
const routes = {
154-
'content-api': {
155-
type: 'content-api',
156-
routes: contentAPIRoutes,
157-
},
157+
'content-api': contentAPIRoutes,
158+
admin: adminAPIRoutes,
158159
};
159160
160161
export default routes;
@@ -307,31 +308,32 @@ const JAVASCRIPT = (pluginName: string): TemplateFile[] => [
307308
`,
308309
},
309310
{
310-
name: 'server/src/routes/content-api.js',
311+
name: 'server/src/routes/content-api/index.js',
311312
contents: outdent`
312-
export default [
313-
{
314-
method: 'GET',
315-
path: '/',
316-
// name of the controller file & the method.
317-
handler: 'controller.index',
318-
config: {
319-
policies: [],
320-
},
321-
},
322-
];
313+
export default () => ({
314+
type: 'content-api',
315+
routes: [],
316+
});
317+
`,
318+
},
319+
{
320+
name: 'server/src/routes/admin/index.js',
321+
contents: outdent`
322+
export default () => ({
323+
type: 'admin',
324+
routes: [],
325+
});
323326
`,
324327
},
325328
{
326329
name: 'server/src/routes/index.js',
327330
contents: outdent`
328331
import contentAPIRoutes from './content-api';
332+
import adminAPIRoutes from './admin';
329333
330334
const routes = {
331-
'content-api': {
332-
type: 'content-api',
333-
routes: contentAPIRoutes,
334-
},
335+
'content-api': contentAPIRoutes,
336+
admin: adminAPIRoutes,
335337
};
336338
337339
export default routes;

0 commit comments

Comments
 (0)