使用Spring前端端点无法构建和部署React

问题描述

我在前端应用程序(反应)中包含的端点有问题。 首先,我先构建前端应用程序,然后在后端应用程序mvn clean install中运行java -jar .jar

应用程序在“ localhost”中运行,但是当我想更改端点时,我已经知道了:

Whitelabel Error Page

This application has no explicit mapping for /error,so you are seeing this as a fallback.
Fri Oct 09 12:43:58 CEST 2020
There was an unexpected error (type=Not Found,status=404).

App.js

function App() {
  return (
    <>
    <Router>
            <Route exact path="/" component={ChooseApplication}/>
            <Route exact path="/core/register" component={RegisterPage}/>
            <Route exact path="/core/login" component={LoginPage}/>
            <Route exact path="/core/presite" component={Presite}/>
            <Route exact path="/library" component={Library}/>
            <Route exact path="/panel/landing" component={Landing}/>
            <Route exact path="/panel/map" component={MapEndpoint}/>
            <Route exact path="/panel/documents" component={DocumentsEndpoint}/>
    </Router>
    </>
  );
}

export default App;

package.json


  "name": "panel","version": "0.1.0","private": true,"dependencies": {
    "@material-ui/core": "^4.11.0","@material-ui/icons": "^4.9.1","@testing-library/jest-dom": "^4.2.4","@testing-library/react": "^9.5.0","@testing-library/user-event": "^7.2.1","axios": "^0.19.2","axios-progress-bar": "^1.2.0","http-proxy-middleware": "^1.0.5","jQuery": "^1.7.4","material-ui": "^0.20.2","ol": "^6.4.2","react": "^16.13.1","react-dom": "^16.13.1","react-openlayers": "^0.3.0","react-scripts": "3.4.1","styled-components": "^5.2.0"
  },"scripts": {
    "start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
  },"eslintConfig": {
    "extends": "react-app"
  },"browserslist": {
    "production": [
      ">0.2%","not dead","not op_mini all"
    ],"development": [
      "last 1 chrome version","last 1 firefox version","last 1 safari version"
    ]
  },"devDependencies": {
    "jquery": "^3.5.1","parcel-bundler": "^1.12.4","react-router-dom": "^5.2.0"
  },"devServer": {
    "proxy": {
      "/panel/*": {
        "target": "http://[::1]:8080"
      }
    }
  }
}

以及在Spring应用程序中:

POM.xml

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.6</version>
                <configuration>
                    <workingDirectory>admin_panel_front</workingDirectory>
                    <installDirectory>target</installDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>v8.9.4</nodeVersion>
                            <npmVersion>5.6.0</npmVersion>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm run build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <groupId>org.apache.maven.plugins</groupId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <copy todir="${project.build.directory}/classes/public">
                                    <fileset dir="${project.basedir}/admin_panel_front/build"/>
                                </copy>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

和在application.properties中

application.properties

server.port=80

我不知道这是因为代理无法重定向到带有端点的正确主机吗?

您有解决此问题的想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)