我的应用程序使用express / nodejs后端和reactjs前端。
每当我在应用程序的生产版本中登录/注销(即按/ auth-outlook等)路由时,该路由都会在搜索栏中更新,但不会更新实际的应用程序路由。
这是我的 routes.js :
module.exports = app => {
app.get('*', (req, res)=>{
res.sendFile(path.join(__dirname, "../client/build/index.html"));
});
app.get("/api/logout", (req, res) => {
req.logout();
res.redirect("/");
});
app.get("/api/current_user", (req, res) => {
res.send(req.user);
});
app.get(
"/auth/outlook",
passport.authenticate("windowslive", {
scope: [
"openid",
"profile",
"offline_access",
"https://outlook.office.com/Mail.Read"
]
})
);
app.get("/authorize-outlook", passport.authenticate("windowslive"), function(
req,
res
) {
res.redirect("/");
});
};
我的 server.js 文件包含以下几行:
app.use(express.static(path.join(__dirname, 'client/build')));
require("./routes/authRoutes")(app);
为了清楚起见,我在路由文件中省略了SQL调用。
此应用程序运行其开发版本(即分别为npm run start
和nodemon server.js
时,可以按预期的方式工作100%。
项目的基本文件结构:
TLDR:应用程序身份验证路由在我的项目的生产版本中不起作用,但在开发版本中起作用。
我们将不胜感激任何信息。
编辑:
这是一个在后端使用React用法的示例:
import React from 'react';
import Particles from 'react-particles-js';
import '../styles/landing.css';
const params = {
particles: {
number: {
value: 100,
density: {
enable: true,
value_area: 800
}
},
color: {
value: '#cccccc'
},
shape: {
type: 'circle',
stroke: {
width: 0,
color: '#cccccc'
},
polygon: {
nb_sides: 5
}
},
opacity: {
value: 0.5,
random: false,
anim: {
enable: false,
speed: 1,
opacity_min: 0.1,
sync: false
}
},
size: {
value: 3,
random: true,
anim: {
enable: false,
speed: 40,
size_min: 0.1,
sync: false
}
},
line_linked: {
enable: true,
distance: 150,
color: '#cccccc',
opacity: 0.4,
width: 1
},
move: {
enable: true,
speed: 6,
direction: 'none',
random: false,
straight: false,
out_mode: 'out',
bounce: false,
attract: {
enable: false,
rotateX: 600,
rotateY: 1200
}
}
},
interactivity: {
detect_on: 'canvas',
events: {
onhover: {
enable: true,
mode: 'repulse'
},
onclick: {
enable: true,
mode: 'push'
},
resize: true
},
modes: {
grab: {
distance: 400,
line_linked: {
opacity: 1
}
},
bubble: {
distance: 400,
size: 40,
duration: 2,
opacity: 8,
speed: 3
},
repulse: {
distance: 200,
duration: 0.4
},
push: {
particles_nb: 4
},
remove: {
particles_nb: 2
}
}
}
};
const Testing = () => (
<div style={{ height: '100vh' }}>
<div id="particles">
<Particles
params={params}
style={{
background:
'linear-gradient(90deg, rgba(136,133,191,1) 0%, rgba(19,155,166,1) 45%, rgba(0,212,255,1) 100%)',
padding: '0!important'
}}
/>
<div className="centered">
<h1 className="headingLg">TQS Travel</h1>
<p>
Travel, made <i>easy</i>.
</p>
<div
className="btn-group center"
role="group"
aria-label="Basic example"
>
<button
type="button"
className="btn btn-light btn-lg"
style={{ marginRight: 10, color: 'black', width: 150 }}
>
<a
className="nav-link"
href="/auth/outlook"
style={{ color: 'black' }}
>
Login
</a>
</button>
<button type="button" className="btn btn-secondary btn-lg">
Request Access
</button>
</div>
</div>
</div>
</div>
);
export default Testing;