将问题简化为最简单的形式:
$ lein new reagent experiment
$ cd experiment
$ lein do clean, uberjar
$ cat >index.html <<EOF
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="resources/public/css/site.css" rel="stylesheet" type="text/css">
</head>
<body class="body-container">
Hello World
<div id="app">
<script src="target/cljsbuild/public/js/app.js" type="text/javascript"></script>
</div>
</body>
</html>
EOF
将浏览器指向localhost:5000在使用'foreman start'时有效,但在使用nginx时则无效。 (意思是,将此目录放在由nginx提供的目录中将加载css和js,将显示“Hello World”,但javascript有错误。)以下两个错误出现在浏览器的控制台中:
app.js:451 Error rendering component (in Vn)
(anonymous) @ app.js:451
app.js:471 Uncaught Error: Assert failed: Invalid Hiccup form: [nil]
(in Vn)
(valid-tag? tag)
at Mk (app.js:471)
at Jk (app.js:473)
at Dk (app.js:475)
at Ik (app.js:470)
at Mk (app.js:472)
at Jk (app.js:473)
at bk (app.js:449)
at app.js:451
at uj (app.js:428)
at vj (app.js:429)
at Tj (app.js:448)
at t.render (app.js:451)
at p._renderValidatedComponentWithoutOwnerOrContext (app.js:25)
at p._renderValidatedComponent (app.js:25)
at performInitialMount (app.js:25)
at p.mountComponent (app.js:25)
at Object.mountComponent (app.js:27)
at performInitialMount (app.js:25)
at p.mountComponent (app.js:25)
at Object.mountComponent (app.js:27)
at i (app.js:26)
at r.perform (app.js:27)
at u (app.js:26)
at r.perform (app.js:27)
at Object.batchedUpdates (app.js:26)
at Object.a [as batchedUpdates] (app.js:27)
at Object._renderNewRootComponent (app.js:26)
at Object._renderSubtreeIntoContainer (app.js:26)
at Sk (app.js:476)
at app.js:554
at app.js:554
at app.js:555
答案 0 :(得分:0)
好的,我相信你的nginx配置正在破坏客户端秘书路由。如您所述,如果从文件系统加载文件(file://.../index.html),则会发生类似的错误。
默认试剂模板未提供的一件事是&#34; ... / index.html&#34;的默认路线。我怀疑这可能有助于nginx案例。我将以下内容添加到src / cljs / experiment / core.cljs并重建:
(secretary/defroute "/index.html" []
(session/put! :current-page #'home-page))
通过这个更改,我能够使用标准的nginx docker容器(然后浏览到localhost:5001)来成功加载页面:
docker run --name nginx -v `pwd`:/usr/share/nginx/html:ro -d -p 5001:80 nginx
您可能希望将该nginx泊坞窗映像的默认配置与您自己的配置进行比较,以确定问题的根本原因。
答案 1 :(得分:0)
这里有两个问题,其中卡纳卡的帮助都有助于挖掘出来。
对此的一个解决方案是修改#&#39;当前页面:
(defn current-page []
[:div (or (session/get :current-page) #'home-page)])
当没有任何内容匹配时,这会让我们进入主页,并解决问题#1(我们不再需要额外的defroute&#34; /index.html")。
我说&#34;一个解决方案&#34;因为当您点击链接时,网址栏将再次假设它不在根目录下,例如,点击关于链接,网址栏将显示 / about ,而不是 /实验/约即可。一切正常,因为它没有去服务器加载错误的网址,但书签它将无法正常工作。肯定有另一种方法可以解决这个问题,但现在这足以解决这两个问题。
再次感谢kanaka!