I'm really liking Nuxts new server/api folder, but i've been trying to figure out if there is anyway to import a module that is available for use in every endpoint (so I don't have to import it everytime).
This is particularly useful for modules that are used in almost every endpoint (like moment for example)
For example in a file like this
/server/api/create-event.js
import moment from 'moment'
export default defineEventHandler(async event => {
console.log(moment().format(), 'creating event at this time');
})
I would want to simplify it down to:
export default defineEventHandler(async event => {
console.log(moment().format(), 'creating event at this time');
})
So there is no need for an import moment in every single endpoint.
I tried setting up the server middleware but that seems to apply more to the routes then the server function. I'm not sure if it's even possible at the moment but would be very useful.