繁体   English   中英

如何从 spring 引导应用程序提供 NextJs 应用程序?

[英]How do I serve the NextJs application from spring boot application?

我有一个 spring 启动 rest API 服务运行在 tomcat。

我有一个在 node.js 服务器上运行的 NextJS UI 应用程序。

现在我希望我的 NextJs 应用程序由 tomcat 服务器提供服务。

要让 spring 引导 static 文件夹为我的 nextjs 应用程序提供服务,我需要执行哪些必要步骤?

我找到了答案。

步骤-1:编辑package.json -> 在scripts属性中添加“export”:“next export”

步骤 - 2:以上步骤将建立一个名为“out”的文件夹。 复制out文件夹的内容。 将其粘贴到src -> main -> resources -> static 文件夹中。

步骤-3:现在构建 spring 引导 jar/war,然后运行它。 它将提供 static 文件夹中的内容。

Springboot 有一个写得很好的例子,说明如何将 React 与 Spring-Data-Rest 和 mvn 插件结合使用来编译/构建你的前端。

我知道 ReactJs 不是 NextJS,但它可能会有所帮助并且可以为您提供一个开始:

maven插件是: frontend-maven-plugin

<build>
    <pluginManagement>
        <plugins>
            <!-- tag::frontend-maven-plugin[] -->
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.9.1</version>
                <configuration>
                    <installDirectory>target</installDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>v12.14.0</nodeVersion>
                            <npmVersion>6.13.4</npmVersion>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>webpack build</id>
                        <goals>
                            <goal>webpack</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- end::frontend-maven-plugin[] -->
        </plugins>
    </pluginManagement>
</build>

https://spring.io/guides/tutorials/react-and-spring-data-rest/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM