添加一个express使用处理程序,该处理程序更改基本路由。

huangapple go评论70阅读模式
英文:

Add an express use handler that changes the base route

问题

我有一个Svelte/SvelteKit应用程序。它说你可以像这样使用你的应用程序

import { handler } from './build/handler.js';
app.use(handler);

但我已经在这个Express服务器中有另一个应用程序,例如

app.use(otherhandler)

所以我希望有一种方法可以这样做

app.use('/newapp', svelte)

它可以工作,但是,如果你没有登录,我的Svelte应用程序会自动重定向到/login。因此,Express应用程序立即重定向到/login,而我希望它能够跳转到/newapp/login。有办法做到这一点吗?

英文:

I have a svelte/sveltekit app. It says you could just your app like so

import { handler } from './build/handler.js';
app.use(handler);

But I already have another app in this express server, eg

app.use(otherhandler)

So I was hoping there was a way to do this

app.use('/newapp', svelte)

And it works, but, my svelte app has an auto redirect to /login if you are not logged in. So then the express app immediately redirects to /login whereas I was hoping it would go to /newapp/login. Is there a way to do this?

答案1

得分: 3

当您使用不同的基础路径时,您可能需要通过config.kit.paths.base来配置,然后可以从$apps/path导入并添加到各种链接和重定向中(至少在UI中,根据文档所述,这是必要的)。

英文:

When you have a different base, you probably should configure that via config.kit.paths.base which then can be imported from $apps/path and added to the various links and redirects (at the very least in the UI this will be necessary, as stated by the docs).

huangapple
  • 本文由 发表于 2023年1月7日 01:13:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75034050.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定