Skip to content

Commit

Permalink
fix: handle url paths without path.join since it uses OS path separat…
Browse files Browse the repository at this point in the history
…or, closes #775
  • Loading branch information
felixmosh committed Jun 24, 2024
1 parent 549364a commit 08f85c5
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/hono/src/HonoAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,39 +163,38 @@ export class HonoAdapter implements IServerAdapter {
}

registerPlugin() {
const { staticRoute, staticPath, entryRoute, viewPath, uiConfig } = this;

if (!staticRoute || !staticPath) {
if (!this.staticRoute || !this.staticPath) {
throw new Error(`Please call 'setStaticPath' before using 'registerPlugin'`);
} else if (!entryRoute) {
} else if (!this.entryRoute) {
throw new Error(`Please call 'setEntryRoute' before using 'registerPlugin'`);
} else if (!viewPath) {
} else if (!this.viewPath) {
throw new Error(`Please call 'setViewsPath' before using 'registerPlugin'`);
} else if (!uiConfig) {
} else if (!this.uiConfig) {
throw new Error(`Please call 'setUIConfig' before using 'registerPlugin'`);
}

const app = new Hono();

const staticBaseUrlPath = [this.basePath, this.staticPath].join('/').replace(/\/{2,}/g, '/');
app.get(
`${staticRoute}/*`,
`${this.staticRoute}/*`,
this.serveStatic({
root: path.relative(process.cwd(), staticPath),
rewriteRequestPath: (p: string) => p.replace(path.join(this.basePath, staticRoute), ''),
root: path.relative(process.cwd(), this.staticPath),
rewriteRequestPath: (p: string) => p.replace(staticBaseUrlPath, ''),
manifest: this.manifest,
})
);

app.route('/', this.apiRoutes);

const routeOrRoutes = entryRoute.route;
const routeOrRoutes = this.entryRoute.route;
const routes = Array.isArray(routeOrRoutes) ? routeOrRoutes : [routeOrRoutes];

routes.forEach((route) => {
app[entryRoute.method](route, async (c: Context) => {
const { name: fileName, params } = entryRoute.handler({
app[this.entryRoute!.method](route, async (c: Context) => {
const { name: fileName, params } = this.entryRoute!.handler({
basePath: this.basePath,
uiConfig,
uiConfig: this.uiConfig ?? {},
});

const template = await ejs.renderFile(`${this.viewPath}/${fileName}`, params);
Expand Down

0 comments on commit 08f85c5

Please sign in to comment.