私はSpring Bootアプリケーションのサインアップエンドポイントを持っています。 UIはReact Single Page Appです。Spring起動時にシングルページアプリケーションをリダイレクトする方法は?
SPAアプリを「/ログイン」(GETリクエスト)にリダイレクトしたいと考えています。
どうすればよいですか?
Iは、次の2つのアプローチを試みた:
最初のアプローチは、郵便配達に応答HTTPコードとして機能しないが200であり、本体のみ「リダイレクト:/ログイン」を含む私は
@RequestMapping(value = "/signup", method = RequestMethod.POST)
public String signup(@RequestBody CustomUserDetails user, HttpServletResponse response) {
String userName = user.getUsername();
logger.debug("User signup attempt with username: " + userName);
try{
if(customUserDetailsService.exists(userName))
{
logger.debug("Duplicate username " + userName);
return "redirect:/login";
} else {
customUserDetailsService.save(user);
authenticateUserAndSetSession(user, response);
}
} catch(Exception ex) {
}
return "redirect:/login";
}
を次のアプローチも試みました。しかし、それはMethod Not Allowed
例外をスローします。要求は、私はこれがリダイレクト扱うことになっていますどのように
@RequestMapping(value = "/signup", method = RequestMethod.POST)
public ModelAndView signup(@RequestBody CustomUserDetails user, ModelMap model, HttpServletResponse response) {
String userName = user.getUsername();
logger.debug("User signup attempt with username: " + userName);
try{
if(customUserDetailsService.exists(userName))
{
logger.debug("Duplicate username " + userName);
return new ModelAndView("redirect:/login", model);
} else {
customUserDetailsService.save(user);
authenticateUserAndSetSession(user, response);
}
} catch(Exception ex) {
}
return new ModelAndView("redirect:/redirectedUrl", model);
}
タイプPOST
であるとき、私はlogin
するためのコントローラを持っているので?ベストプラクティスは何ですか?
既存のエラーコードを送信する場合はどうすればよいですか?ユーザー名? –
フロントエンドで処理する限り、任意のステータスコードを送信できます。 – shazin
ログアウトはどうですか? SPAでどのように処理すればよいですか?ヘッダーにJWT(認証トークン)を置くことを止めたらどうですか? –