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