Closed camfeghali closed 1 year ago
Hi @camfeghali
My immediate thought is that it might be an issue with how you are importing your log
function. You are importing it from "../other-dir/index.ts"
. You should just import it without the extension, eg. "../other-dir"
(no need for /index since it's the index file of the folder). But if you want to use the ES import syntax then it needs to be "../other-dir/index.js"
as that is the compiled file, and trying to import the uncompiled typescript file will fail.
hey @kasperkristensen , thanks for the help, it worked!
@camfeghali Glad to hear it! 💪
Bug report
Edit: This happens when I define functions in a file outside of the
src/api/admin/custom
folder, and import & execute them in the/route.ts
file. Is there something to know about project level scope here?Describe the bug
I am receiving a
404 Cannot GET /admin/custom
when making a GET request to my custom API route even though I export aconst AUTHENTICATION=false
.To clarify - when using Postman:
x-medusa-access-token
, I receive a 404 Error page withCannot GET /admin/custom
x-medusa-access-token
, I receive aUnauthorized
message.System information
Medusa packages:
Node.js version:
16.0.0
Database: postgresql Operating system: MACSteps to reproduce the behavior
src/api/admin/custom/route.ts
/custom
dir. ex:export function log(){console.log("hello world")}
route.ts
file:export const GET = (req: MedusaRequest, res: MedusaResponse) => { log(); res.json({ message: '[GET] Hello world!', }); };
export const AUTHENTICATE = true;
curl --location 'http://localhost:9000/admin/custom' \ --header 'x-medusa-access-token:' \
--header 'Cookie: connect.sid=s%3AIuVcge8cY2Z-raq7E68lakY8NScmE2r4.b4LKiAa8uZOcTalLrQH%2By5%2FcWuZMfxmPT43vJ54ceWI; session=MTY5Njg3Njc1NXxEdi1CQkFFQ180SUFBUkFCRUFBQUhmLUNBQUVHYzNSeWFXNW5EQWdBQm5WelpYSkpSQU5wYm5RRUFnQU18fkpJ6zbUKrZzRy0-l_g8ZnV7uidAhQ6K_8EnLjRjbD8='