Can't setup custom path for functions

I’m trying to setup a custom path to access my functions.

This is the code:

import type { Config, Handler } from "@netlify/functions";

export const handler: Handler = async (event, context) => {
  return {
    body: JSON.stringify({ message: "Hello World" }),
    statusCode: 200,
  };
};

export const config: Config = {
  path: "/api/hello",
};

I’m running it locally using the command netlify functions:serve and the proof that work is that I can access the function using https://localhost:9999/.netlify/functions/hello but can’t on https://localhost:9999/api/hello (see screenshot attached for evidence).

image

I don’t feel like I’m doing something wrong, is this a bug?

@TulioPintoNeto Where did you encounter that path configuration in the documentation?

What I see for setting up aliases for functions is using rewrites:

@nathanmartin here: Get started with functions | Netlify Docs

Netlify even provide this Config type, and if you check the code itself, it tells about the path configuration:

image

@TulioPintoNeto Thanks, I’d never encountered anyone using that feature before and figured that you were looking at the documentation but I simply couldn’t spot it.

@hrishikesh Can you confirm if this feature is working as intended?

Does this work for you when you run netlify dev as opposed to functions:serve?

So, firstly I tried to run netlify dev, but I was never able to get this working (please see screenshot attached).

image

Hi @hrishikesh and @nathanmartin. Is there any other details I may provide to help resolving this?

The issue that you’re running into seems to be this: fix missing .netlify/edge-functions/angular-ssr by hrishikesh-k · Pull Request #106 · netlify/angular-runtime (github.com)

But the functions:serve sounds like a bug in the CLI to me.

1 Like

The issue with netlify dev has been fixed in v2.0.7 of @netlify/angular-runtime. However, I tried your repo after that and any requests to /api/activties gets redirected back to home page. It’s possible that the path is being consumed by Angular and therefore it’s not hitting the Function.

For the original issue, you might have to file a bug on the CLI repo.

Actually, that might currently be expected based on this comment: cli/src/lib/functions/server.ts at main · netlify/cli (github.com)

Hey @hrishikesh, currently the package library for @netlify/angular-runtime says that:

Netlify automatically detects Angular projects and sets up the latest version of this plugin. There’s no further configuration needed from Netlify users.

So currently I have no control over the version Netlify is using for this package, in my project, as my only dependency declared is with @netlify/functions. I’m still getting the same error of missing folder, two questions regarding this:

  • Maybe I missed some setting up? FWIW I used everything from this Getting Started;
  • If I didn’t miss anything, is there a correctly way to enforce Netlify to pick the new version (2.0.7)?

Thanks for clarifying, I didn’t know CLI was a different support, I’ll open an issue there then.

Still thought, I appreciate if you can help me getting sorted with netlify dev working locally, I definitely want to have that.

Thanks for all the help so far, you’re being really helpful

You can always download and install a package from npm. Since it’s already published as the latest version, it should be used as that one. Try deleting your .netlify folder.

For those who want to follow this discussion to CLI package on GitHub:

1 Like

I’ve also ran into the same issue where the custom path routing doesn’t work at all. Any update on how to fix this?

Ticket #306992 – Netlify – Zendesk

@acorn-brandon, your issue was a code issue on your end - unrelated to this old thread.