mirror of
https://github.com/usatiuk/y.git
synced 2025-10-28 02:27:49 +01:00
pain and suffering
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
"start": "parcel",
|
"start": "parcel",
|
||||||
"build": "parcel build"
|
"build": "parcel build"
|
||||||
},
|
},
|
||||||
|
"publicUrl": "/app",
|
||||||
"browserslist": "> 0.5%, last 2 versions, not dead",
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"jwt-decode": "^4.0.0",
|
"jwt-decode": "^4.0.0",
|
||||||
|
|||||||
@@ -39,95 +39,98 @@ import { Chat } from "./Chat";
|
|||||||
import { ChatEdit } from "./ChatEdit";
|
import { ChatEdit } from "./ChatEdit";
|
||||||
import { Haters } from "./Haters";
|
import { Haters } from "./Haters";
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter(
|
||||||
{
|
[
|
||||||
path: "/",
|
{
|
||||||
loader: async () => {
|
path: "/",
|
||||||
if (getToken() == null) {
|
loader: async () => {
|
||||||
return redirect("/login");
|
if (getToken() == null) {
|
||||||
} else {
|
return redirect("/login");
|
||||||
return redirect("/home");
|
} else {
|
||||||
}
|
return redirect("/home");
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
path: "/home",
|
||||||
path: "/home",
|
loader: homeLoader,
|
||||||
loader: homeLoader,
|
action: homeAction,
|
||||||
action: homeAction,
|
element: <Home />,
|
||||||
element: <Home />,
|
children: [
|
||||||
children: [
|
{ path: "feed", element: <Feed />, loader: feedLoader },
|
||||||
{ path: "feed", element: <Feed />, loader: feedLoader },
|
// { path: "messages", element: <Messages /> },
|
||||||
// { path: "messages", element: <Messages /> },
|
{
|
||||||
{
|
path: "messages/chats",
|
||||||
path: "messages/chats",
|
element: <Chats />,
|
||||||
element: <Chats />,
|
loader: chatListLoader,
|
||||||
loader: chatListLoader,
|
},
|
||||||
},
|
{
|
||||||
{
|
path: "messages/chats/new",
|
||||||
path: "messages/chats/new",
|
element: <ChatCreate />,
|
||||||
element: <ChatCreate />,
|
loader: newChatLoader,
|
||||||
loader: newChatLoader,
|
action: newChatAction,
|
||||||
action: newChatAction,
|
},
|
||||||
},
|
{
|
||||||
{
|
path: "messages/chat/:id",
|
||||||
path: "messages/chat/:id",
|
element: <Chat />,
|
||||||
element: <Chat />,
|
loader: chatLoader,
|
||||||
loader: chatLoader,
|
action: chatAction,
|
||||||
action: chatAction,
|
},
|
||||||
},
|
{
|
||||||
{
|
path: "messages/chat/:id/edit",
|
||||||
path: "messages/chat/:id/edit",
|
element: <ChatEdit />,
|
||||||
element: <ChatEdit />,
|
loader: editChatLoader,
|
||||||
loader: editChatLoader,
|
action: editChatAction,
|
||||||
action: editChatAction,
|
},
|
||||||
},
|
{
|
||||||
{
|
path: "users",
|
||||||
path: "users",
|
element: <UserList />,
|
||||||
element: <UserList />,
|
loader: userListLoader,
|
||||||
loader: userListLoader,
|
action: userListAction,
|
||||||
action: userListAction,
|
},
|
||||||
},
|
{
|
||||||
{
|
path: "profile",
|
||||||
path: "profile",
|
loader: profileLoader,
|
||||||
loader: profileLoader,
|
action: profileSelfAction,
|
||||||
action: profileSelfAction,
|
element: <Profile self={true} />,
|
||||||
element: <Profile self={true} />,
|
},
|
||||||
},
|
{
|
||||||
{
|
path: "profile/:username",
|
||||||
path: "profile/:username",
|
loader: profileLoader,
|
||||||
loader: profileLoader,
|
// action: profileSelfAction,
|
||||||
// action: profileSelfAction,
|
element: <Profile self={false} />,
|
||||||
element: <Profile self={false} />,
|
},
|
||||||
},
|
{
|
||||||
{
|
path: "haters",
|
||||||
path: "haters",
|
element: <Haters />,
|
||||||
element: <Haters />,
|
},
|
||||||
},
|
],
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/login",
|
|
||||||
element: <Login />,
|
|
||||||
loader: async () => {
|
|
||||||
if (getToken()) {
|
|
||||||
return redirect("/");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
action: loginAction,
|
{
|
||||||
},
|
path: "/login",
|
||||||
{
|
element: <Login />,
|
||||||
path: "/signup",
|
loader: async () => {
|
||||||
element: <Signup />,
|
if (getToken()) {
|
||||||
loader: async () => {
|
return redirect("/");
|
||||||
if (getToken()) {
|
}
|
||||||
return redirect("/");
|
return null;
|
||||||
}
|
},
|
||||||
return null;
|
action: loginAction,
|
||||||
},
|
},
|
||||||
action: signupAction,
|
{
|
||||||
},
|
path: "/signup",
|
||||||
]);
|
element: <Signup />,
|
||||||
|
loader: async () => {
|
||||||
|
if (getToken()) {
|
||||||
|
return redirect("/");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
action: signupAction,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ basename: "/app" },
|
||||||
|
);
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -3,7 +3,14 @@
|
|||||||
import { jwtDecode } from "jwt-decode";
|
import { jwtDecode } from "jwt-decode";
|
||||||
import { isError } from "./dto";
|
import { isError } from "./dto";
|
||||||
|
|
||||||
const apiRoot: string = "http://localhost:8080";
|
declare const process: {
|
||||||
|
env: {
|
||||||
|
NODE_ENV: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiRoot: string =
|
||||||
|
process.env.NODE_ENV == "production" ? "/" : "http://localhost:8080";
|
||||||
|
|
||||||
let token: string | null;
|
let token: string | null;
|
||||||
|
|
||||||
|
|||||||
50
server/src/main/java/com/usatiuk/tjv/y/server/WebConfig.java
Normal file
50
server/src/main/java/com/usatiuk/tjv/y/server/WebConfig.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package com.usatiuk.tjv.y.server;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.http.CacheControl;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
import org.springframework.web.servlet.resource.ResourceResolver;
|
||||||
|
import org.springframework.web.servlet.resource.ResourceResolverChain;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
|
static class AppResourceResolver implements ResourceResolver {
|
||||||
|
@Override
|
||||||
|
public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain) {
|
||||||
|
ClassPathResource res = new ClassPathResource("/app/" + requestPath);
|
||||||
|
if (res.exists()) return res;
|
||||||
|
ClassPathResource indexRes = new ClassPathResource("/app/index.html");
|
||||||
|
if (indexRes.exists()) return indexRes;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resolveUrlPath(String resourcePath, List<? extends Resource> locations, ResourceResolverChain chain) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addViewControllers(ViewControllerRegistry registry) {
|
||||||
|
registry.addRedirectViewController("/app/", "/app/index.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("/app/**")
|
||||||
|
.setCacheControl(CacheControl.maxAge(Duration.ofDays(365)))
|
||||||
|
.resourceChain(true)
|
||||||
|
.addResolver(new AppResourceResolver());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,6 +59,7 @@ public class WebSecurityConfig {
|
|||||||
.authorizeHttpRequests((authorize) -> authorize
|
.authorizeHttpRequests((authorize) -> authorize
|
||||||
.requestMatchers(mvc.pattern(HttpMethod.POST, "/person")).permitAll()
|
.requestMatchers(mvc.pattern(HttpMethod.POST, "/person")).permitAll()
|
||||||
.requestMatchers(mvc.pattern(HttpMethod.POST, "/token")).permitAll()
|
.requestMatchers(mvc.pattern(HttpMethod.POST, "/token")).permitAll()
|
||||||
|
.requestMatchers(mvc.pattern("/app/**")).permitAll()
|
||||||
.requestMatchers(mvc.pattern("/swagger-ui*/**")).permitAll()
|
.requestMatchers(mvc.pattern("/swagger-ui*/**")).permitAll()
|
||||||
.requestMatchers(mvc.pattern("/v3/**")).permitAll()
|
.requestMatchers(mvc.pattern("/v3/**")).permitAll()
|
||||||
.requestMatchers(mvc.pattern("/error")).permitAll()
|
.requestMatchers(mvc.pattern("/error")).permitAll()
|
||||||
|
|||||||
Reference in New Issue
Block a user