chore: try relative dynamic import
This commit is contained in:
parent
5af6747c29
commit
8b3b7fdfa2
1 changed files with 18 additions and 2 deletions
|
@ -4,6 +4,8 @@ import { createHooks } from 'hookable'
|
||||||
import { consola } from 'consola'
|
import { consola } from 'consola'
|
||||||
import { colorize } from 'consola/utils'
|
import { colorize } from 'consola/utils'
|
||||||
import { useRuntimeConfig } from 'nitropack/runtime'
|
import { useRuntimeConfig } from 'nitropack/runtime'
|
||||||
|
import { dirname, relative } from 'pathe'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
hooks as mcflyHooks,
|
hooks as mcflyHooks,
|
||||||
|
@ -28,17 +30,31 @@ export default eventHandler(async (event) => {
|
||||||
const hooks = createHooks()
|
const hooks = createHooks()
|
||||||
Object.keys(mcflyHooks).forEach((hookName) => hooks.addHooks(hookName))
|
Object.keys(mcflyHooks).forEach((hookName) => hooks.addHooks(hookName))
|
||||||
const { path } = event
|
const { path } = event
|
||||||
|
const storage = useStorage()
|
||||||
|
|
||||||
const { appConfigFile } = useRuntimeConfig()
|
const { appConfigFile } = useRuntimeConfig()
|
||||||
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
|
const __dirname = dirname(__filename)
|
||||||
|
let relativePath = relative(__dirname, appConfigFile)
|
||||||
|
relativePath = relativePath.replace('.mjs', '').replace('../', '')
|
||||||
|
|
||||||
|
console.log('>>> relative', relativePath)
|
||||||
|
|
||||||
let config
|
let config
|
||||||
// TODO: this still doesn't work on Netlify
|
// TODO: this still doesn't work on Netlify
|
||||||
try {
|
try {
|
||||||
let { default: configFn } = await import(appConfigFile)
|
const { default: configFn } = await import(`../${relativePath}.mjs`)
|
||||||
config = configFn()
|
config = configFn()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
consola.error(err)
|
consola.error(err)
|
||||||
}
|
}
|
||||||
const storage = useStorage()
|
|
||||||
|
console.log('>>> ', {
|
||||||
|
config,
|
||||||
|
appConfigFile,
|
||||||
|
relativePath: `../${relativePath}.mjs`,
|
||||||
|
__dirname,
|
||||||
|
})
|
||||||
|
|
||||||
// if not page, don't render
|
// if not page, don't render
|
||||||
if (event.path.startsWith('/api')) {
|
if (event.path.startsWith('/api')) {
|
||||||
|
|
Loading…
Reference in a new issue