【发布时间】:2021-12-01 15:36:17
【问题描述】:
我对 Jetty 和 Vaadin 很陌生。我尝试让 Jetty 运行托管一个最小的 Vaadin Fusion 示例。
但是,第一次访问我的空 index.html 时,我得到了 connection lost 横幅和 404,因为它试图重定向到 /offline-stub .html 我没有。
生产者视图:
在网络点击中,您可以看到 Vaadin 以某种方式启动了重定向:
我的 index.html 很简单:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Vaadin Grocery App</title>
<style>
body {
margin: 0;
width: 100vw;
height: 100vh;
}
#outlet {
height: 100%;
}
</style>
<!-- index.ts is included here automatically (either by the dev server or during the build) -->
</head>
<body>
<h1>hello</h1>
</body>
</html>
还有一个 index.ts:
import { Router } from '@vaadin/router';
import { routes } from './routes';
import { appStore } from './stores/app-store';
export const router = new Router(document.querySelector('#outlet'));
router.setRoutes(routes);
window.addEventListener('vaadin-router-location-changed', (e) => {
appStore.setLocation((e as CustomEvent).detail.location);
const title = appStore.currentViewTitle;
if (title) {
document.title = title + ' | ' + appStore.applicationName;
} else {
document.title = appStore.applicationName;
}
});
我这样启动 Jetty:
public static void main(String[] args) throws URISyntaxException, IOException {
Log.setLog(new StdErrLog());
System.out.println("Server starting...");
String extForm = webRoot + "/webapp";
System.out.println(extForm);
final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
final ResourceHandler resHandler = new ResourceHandler();
resHandler.setResourceBase(extForm);
final ContextHandler ctx = new ContextHandler("/");
ctx.setHandler(resHandler);
Server embeddedServer = new Server(8080);
embeddedServer.insertHandler(context); // Rest/Servlets
embeddedServer.insertHandler(resHandler); // HTML Resources
try {
embeddedServer.start();
embeddedServer.join();
} catch (Exception e) {
System.err.println("Server error:\n" + e);
}
System.out.println("Server stopped");
}
Webroot, extform - 值正确且文件位于磁盘上的指定位置:
【问题讨论】:
标签: jetty vaadin vaadin-fusion hilla