mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 21:36:26 -08:00
Genius
This commit is contained in:
parent
58883951d3
commit
0bf5f6f985
|
@ -26,22 +26,24 @@ function resolveMount(mount: APIMountResolvable): APIMount {
|
|||
class APIVersion {
|
||||
readonly definition: APIDefinition
|
||||
readonly apiPath: string
|
||||
readonly apiRoot: Hono
|
||||
readonly root: Hono = new Hono()
|
||||
readonly files: Files
|
||||
|
||||
constructor(definition: APIDefinition, files: Files) {
|
||||
constructor(definition: APIDefinition, files: Files, apiRoot: Hono) {
|
||||
this.definition = definition
|
||||
this.apiPath = APIDirectory + "/" + definition.name
|
||||
this.files = files
|
||||
this.apiRoot = apiRoot
|
||||
}
|
||||
|
||||
async load() {
|
||||
for (let _mount of this.definition.mount) {
|
||||
let mount = resolveMount(_mount);
|
||||
// no idea if there's a better way to do this but this is all i can think of
|
||||
let { default: route } = await import(`${this.apiPath}/${mount.file}.js`) as { default: (files: Files) => Hono }
|
||||
let { default: route } = await import(`${this.apiPath}/${mount.file}.js`) as { default: (files: Files, apiRoot: Hono) => Hono }
|
||||
|
||||
this.root.route(mount.to, route(this.files))
|
||||
this.root.route(mount.to, route(this.files, this.apiRoot))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +64,7 @@ export default class APIRouter {
|
|||
private async mount(definition: APIDefinition) {
|
||||
console.log(`mounting APIDefinition ${definition.name}`)
|
||||
|
||||
let def = new APIVersion(definition, this.files)
|
||||
let def = new APIVersion(definition, this.files, this.root)
|
||||
await def.load()
|
||||
|
||||
this.root.route(
|
||||
|
|
|
@ -20,9 +20,9 @@ export let primaryApi = new Hono<{
|
|||
|
||||
primaryApi.all("*", getAccount)
|
||||
|
||||
export default function (files: Files) {
|
||||
export default function (files: Files, apiRoot: Hono) {
|
||||
primaryApi.get("/file/:fileId", async (ctx) =>
|
||||
primaryApi.fetch(
|
||||
apiRoot.fetch(
|
||||
new Request(
|
||||
(new URL(
|
||||
`/api/v1/file/${ctx.req.param("fileId")}`, ctx.req.raw.url)).href,
|
||||
|
|
Loading…
Reference in a new issue