我是一个新的节点反应现在我想发送数据从节点js (后端)反应js与响应数据。实际上,我的情况是在注册Google身份验证后,我想将数据发送到React js (前端)。
router.get(
'/auth/google/callback',
passportGoogle.authenticate('google', {
failureRedirect: '/',
}),
(req, res) => {
const nameFirst = req.user.profile._json.displayName;
const picture = req.user.profile._json.image.url;
const email = req.user.profile.emails[0].value;
const id = req.user.profile.id;
const user = new User({
user_token: id,
name: nameFirst,
email: email,
picture: picture,
provider: 'Google',
dateSent: Date.now(),
});
User.findOne({ email: email }, (err, docs) => {
if (docs != null) {
// already exist
} else {
// send data `user` with routing [routing to /signupnext,]
}
});发布于 2019-03-26 00:42:38
您所描述的内容构成了计算机系统之间的一个问题:如何通信。
使用JSON和REST,您可以将REST端点开发为节点服务。
所有的REST端点都是一个以特定方式运行的HTTP服务地址。
您需要做的是在Node应用程序中开发一个REST端点,并使用React应用程序调用该端点。
您不能只是将数据“发送”到客户端应用程序,应用程序必须请求它。
如果您重写了调用,以便您的React.JS调用一个端点,Node.JS将进行身份验证并将结果返回给React,这对您来说应该是有效的。
有关节点rest端点的更多信息:https://www.codementor.io/olatundegaruba/nodejs-restful-apis-in-10-minutes-q0sgsfhbd
https://stackoverflow.com/questions/55342522
复制相似问题