Forge Function - How to reference to handler file in sub-directory

I have a Forge app with this structure:

src
 |-- admin
 |     |-- index.js
 |-- panel
       |-- index.js

How can I define two functions which refer to the handler from those sub-directory, instead of put 2 js files to the src?
The below code does not work for me.

function:
  - key: admin-page-resolver
    handler: admin/index.handler
  - key: panel-handler
    handler: panel/index.run

Thanks!

Based on the error message I see when trying to repro it, I don’t think you can do any sort of pathing in your app’s manifest.yml:

function handler property ‘test/best.handler’ must be in format <module>.<function>

However, a workaround for this might be to have a top-level module that you import all of your sub-modules and functions into.

So your structure becomes:

src
 | -- index.js
 |-- admin
 |     |-- index.js
 |-- panel
       |-- index.js

And then both admin/index.js and panel/index.js export the functions you want to make use of:

export const handler = resolver.getDefinitions();

And your top-level src/index.js imports them:

import { handler } from 'admin';

export const handler;
3 Likes

Thanks, @bcook,

It has been more than a month since this question, and I actually went with that same solution as your answer.

Cheers

1 Like