System Information
- Strapi Version: 4.10.2
- Operating System: Windows 11
- Database: SQLite
- Node Version: v18.15.0
- NPM Version: 9.5.0
- Yarn Version: 1.22.19
Hi all, I’ve found a similar query to mine on stackoverflow which doesn’t seem to have any working answers:
I wasn’t able to find any information on how to do this in the Strapi documentation either. Anyways, here is the issue at hand:
I’ve created a new custom plugin using the yarn strapi generate plugin
command, and the following bits were generated:
src/plugins/my-plugin/server/routes/index.js
module.exports = [
{
method: "GET",
path: "/export",
handler: "myController.index",
config: {
policies: [],
},
},
];
(I modified the path
field to be "/export"
instead of "/"
to help remove some ambiguity.)
src/plugins/my-plugin/server/controllers/my-controller.js
"use strict";
module.exports = ({ strapi }) => ({
index(ctx) {
ctx.body = strapi
.plugin("export-form-submissions")
.service("myService")
.getWelcomeMessage();
},
});
now from my admin page (src/plugins/my-plugin/admin/src/pages/HomePage/index.js), I am trying to call this endpoint:
const handleDownload = async () => {
try {
const response = await fetch(`/export`);
if (response.ok) {
// File downloaded successfully
} else {
// Handle error scenario
}
} catch (error) {
}
};
However when I call this, I always get a 404 error:
[2023-05-29 17:26:36.715] http: GET /export (2 ms) 404
How do I call this endpoint in my routes files from within my admin page, and as a result call the controller method? Am I missing some sort of configuration to make the endpoint public? I’ve tried lots of variations with my routes and admin page code, but haven’t had any luck…
Many thanks