我的暂存环境中的网址是
https://pure-escarpment-97621.herokuapp.com/auth
所以一般情况下,这将返回一个“授权”微调器页面,但在某些情况下,在手机上,我会立即返回404。我会尝试在这里删除一些相关的代码
我的react客户端使用package.json
中的以下代理到我的node / express应用程序 <Route path="/auth" render={(props) => {
console.log("hit auth in client");
this.handleAuthentication(props);
return <Callback auth={auth} {...props} />
}}/>
我的App.js有以下路线
var hdrs = {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${parsedQueryString.access_token}`
};
console.log("about to fetch auth server side from client")
fetch('/auth', {
headers : hdrs,
method: 'post',
})
.then(results => {
// this.setSession(parsedQueryString);
return results.json();
window.location.href = '/';
})
.then(data => {
// console.log("Results = " + JSON.stringify(data));
this.setSession(data);
window.location.href = '/';
})
handleAuthentication执行以下操作(因此调用服务器/身份验证路由)
2018-06-18T19:11:05.259855+00:00 heroku[router]: at=info method=GET path="/auth" host=fierce-savannah-70710.herokuapp.com request_id=5ee04ac9-eaf4-4121-8b1c-6721d891c0b2 fwd="212.159.122.237" dyno=web.1 connect=0ms service=24ms status=404 bytes=380 protocol=http
我不认为这里需要后端的东西,因为它似乎永远不会那么远。事实上,我认为这只是某种奇怪的heroku设置问题,我不明白。
有人有任何想法吗?这真是令人沮丧。
干杯
标记
编辑:
查看访问日志,似乎是service-worker.js的问题
使用手机
2018-06-18T19:12:17.319382+00:00 heroku[router]: at=info method=GET path="/service-worker.js" host=fierce-savannah-70710.herokuapp.com request_id=786c9dc2-0940-4e94-88c7-44ef3542619d fwd="212.159.122.237" dyno=web.1 connect=0ms service=8ms status=304 bytes=237 protocol=https
来自网络
var express = require('express');
var path = require('path');
var session = require('express-session');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var bearerToken = require('express-bearer-token');
var index = require('./routes/index');
var posts = require('./routes/posts');
var users = require('./routes/users');
var auth = require('./routes/auth');
var accounts = require('./routes/accounts')
var mongoose = require('mongoose');
var config = require('./config')
var app = express();
app.use(session({
secret: config.session.secret,
saveUninitialized: true,
resave: false
}));
app.use(bearerToken());
// view engine setup
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'jade');
// Priority serve any static files.
app.use(express.static(path.resolve(__dirname, './client/build')));
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
var dburl = 'mongodb://localhost:27017/curie'
if (config.db_user)
{
dburl = 'mongodb://' + config.db_user + ':' + config.db_pwd + '@' + config.db_url + '/' + config.db_name
}
console.log("connecting to db " + dburl);
mongoose.set('debug', true);
mongoose.connect(dburl, {
useMongoClient: true,
/* other options */
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
//app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, './client/build')));
app.use('/', index);
app.use('/posts', posts);
app.use('/users', users);
app.use('/auth', auth);
app.use('/accounts', accounts);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
// All remaining requests return the React app, so it can handle routing.
app.get('*', function(request, response) {
response.sendFile(path.resolve(__dirname, './client/build', 'index.html'));
});
module.exports = app;
编辑:
app.js
{{1}}