added monolith app build

This commit is contained in:
Alexander Karpov 2024-12-24 03:25:01 +03:00
parent 911c538fb0
commit babf31f4f1
12 changed files with 4789 additions and 136 deletions

25
backend/build-frontend.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
# Go to frontend directory
cd ../frontend
# Install dependencies and build
npm install
npm run build
# Save swagger-ui.html
cd ../backend/src/main/webapp
cp swagger-ui.html /tmp/swagger-ui.html
# Remove old files except WEB-INF
find . -mindepth 1 -maxdepth 1 ! -name 'WEB-INF' -exec rm -rf {} +
# Copy new build files
cp -r ../../../../frontend/build/* .
# Restore swagger-ui.html
cp /tmp/swagger-ui.html .
rm /tmp/swagger-ui.html
# Return to backend directory
cd ../../../../backend

View File

@ -0,0 +1,32 @@
package ru.akarpov.web4.servlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
public class SPARouterServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Set content type
response.setContentType("text/html;charset=UTF-8");
// Read index.html
try (InputStream in = getServletContext().getResourceAsStream("/static/index.html")) {
if (in == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// Copy the index.html content to response
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
response.getOutputStream().write(buffer, 0, bytesRead);
}
}
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/web-lab4</context-root>
</jboss-web>

View File

@ -8,26 +8,16 @@
<welcome-file>index.html</welcome-file> <welcome-file>index.html</welcome-file>
</welcome-file-list> </welcome-file-list>
<!-- REST API -->
<servlet-mapping> <servlet-mapping>
<servlet-name>jakarta.ws.rs.core.Application</servlet-name> <servlet-name>jakarta.ws.rs.core.Application</servlet-name>
<url-pattern>/api/*</url-pattern> <url-pattern>/api/*</url-pattern>
</servlet-mapping> </servlet-mapping>
<!-- Add mime type mappings for Swagger UI --> <!-- Default Servlet -->
<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>application/javascript</mime-type>
</mime-mapping>
<!-- Allow access to Swagger resources -->
<servlet-mapping> <servlet-mapping>
<servlet-name>default</servlet-name> <servlet-name>default</servlet-name>
<url-pattern>/swagger-ui.html</url-pattern> <url-pattern>/</url-pattern>
<url-pattern>/webjars/*</url-pattern>
</servlet-mapping> </servlet-mapping>
</web-app> </web-app>

View File

@ -1,65 +0,0 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Приветственная страница</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f0f2f5;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
.container {
background-color: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 600px;
width: 100%;
text-align: center;
}
h2 {
color: #1a73e8;
margin-bottom: 1rem;
font-size: 2em;
font-weight: bold;
}
p {
color: #5f6368;
font-size: 1.2em;
line-height: 1.5;
margin: 1rem 0;
}
@media (max-width: 480px) {
.container {
padding: 1rem;
}
h2 {
font-size: 1.5em;
}
p {
font-size: 1em;
}
}
</style>
</head>
<body>
<div class="container">
<h2>Вы кто такие?</h2>
<p>Я вас не звал, идите нахуй!</p>
</div>
</body>
</html>

View File

@ -21,10 +21,10 @@
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
"devDependencies": { "devDependencies": {
"autoprefixer": "^10.4.20", "autoprefixer": "^10.4.16",
"postcss": "^8.4.49", "postcss": "^8.4.32",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"tailwindcss": "^3.4.17", "tailwindcss": "^3.4.0",
"typescript": "^4.9.5" "typescript": "^4.9.5"
} }
}, },

View File

@ -2,6 +2,7 @@
"name": "web-lab4-frontend", "name": "web-lab4-frontend",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"homepage": ".",
"dependencies": { "dependencies": {
"@reduxjs/toolkit": "^1.9.7", "@reduxjs/toolkit": "^1.9.7",
"@types/node": "^16.18.0", "@types/node": "^16.18.0",
@ -41,10 +42,10 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"autoprefixer": "^10.4.20", "autoprefixer": "^10.4.16",
"postcss": "^8.4.49", "postcss": "^8.4.32",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"tailwindcss": "^3.4.17", "tailwindcss": "^3.4.0",
"typescript": "^4.9.5" "typescript": "^4.9.5"
} }
} }

View File

@ -1,43 +1,21 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<meta <meta
name="description" name="description"
content="Web site created using create-react-app" content="Web site created using create-react-app"
/> />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!-- <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
manifest.json provides metadata used when your web app is installed on a <base href="%PUBLIC_URL%/" />
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ <title>Web Lab 4</title>
--> </head>
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <body>
<!-- <noscript>You need to enable JavaScript to run this app.</noscript>
Notice the use of %PUBLIC_URL% in the tags above. <div id="root"></div>
It will be replaced with the URL of the `public` folder during the build. </body>
Only files inside the `public` folder can be referenced from the HTML. </html>
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

View File

@ -1,17 +1,17 @@
import React from 'react'; import React from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; import { HashRouter as Router, Routes, Route } from 'react-router-dom';
import StartPage from './pages/StartPage'; import StartPage from './pages/StartPage';
import MainPage from './pages/MainPage'; import MainPage from './pages/MainPage';
function App() { function App() {
return ( return (
<Router> <Router>
<Routes> <Routes>
<Route path="/" element={<StartPage />} /> <Route path="/" element={<StartPage />} />
<Route path="/main" element={<MainPage />} /> <Route path="/main" element={<MainPage />} />
</Routes> </Routes>
</Router> </Router>
); );
} }
export default App; export default App;

View File

@ -1,8 +1,9 @@
import axios from 'axios'; import axios from 'axios';
import { AuthResponse, LoginRequest, RegisterRequest, Point, PointRequest } from '../types'; import { AuthResponse, LoginRequest, RegisterRequest, Point, PointRequest } from '../types';
const BASE_PATH = window.location.pathname.split('/')[1]; // Gets 'web-lab4'
const api = axios.create({ const api = axios.create({
baseURL: 'http://localhost:8080/web-lab4/api', baseURL: `/${BASE_PATH}/api`,
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }

File diff suppressed because it is too large Load Diff