【发布时间】:2018-03-23 20:32:14
【问题描述】:
我正在使用 app id 作为护照解决方案向网站添加登录功能。护照位工作正常。
然而,问题是当我重定向到我的捆绑包所链接的文件 index.html 时,它不会仅显示捆绑包的 html。需要明确的是,它会找到 index.html 文件并加载 html,但不会加载索引文件中的包。但是,如果我的 index.html 是通过 express 自动加载为我的包显示的索引文件。
因此,如果我转到页面基本 url,捆绑包将显示,但如果我进入 /login,然后将我的网站重定向到 /public/index.html,捆绑包不会显示。
这个
app.get('/*',function(req,res,next){
console.log("is user; ")
console.log(req.user)
if (req.user) {
res.sendFile(__dirname + '/public/index.html');
} else {
res.redirect("/login")
}
})
和
const LANDING_PAGE ="/public/index.html";
app.get("/login", passport.authenticate(WebAppStrategy.STRATEGY_NAME, {successRedirect : LANDING_PAGE, forceLogin: true}));
这不会显示捆绑包,而是使用
app.use(express.static(__dirname + '/public'));
自动加载 index.html 并显示捆绑代码。
我的 index.html 文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo react</title>
<link rel="shortcut icon" href="filer/DL_Logo.svg" type="image/svg">
</head>
<body>
<h1>Hello this is kinda working...</h1>
<div id="container"></div>
<script src="/dist/bundle.js" type="text/javascript"></script>
<!-- Resource jQuery -->
</body>
</html>
我没有控制台错误,网络选项卡显示它加载了捆绑 JS 文件。
我认为问题出在 Webpack 捆绑配置或 Express 的某个地方。
【问题讨论】:
-
那是因为你没有包含你的
bundle文件,我猜它目前位于dist。
标签: javascript node.js express webpack passport.js