Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Localhost:3000节点中出现302错误_Javascript_Node.js_Mongodb_Express - Fatal编程技术网

Javascript Localhost:3000节点中出现302错误

Javascript Localhost:3000节点中出现302错误,javascript,node.js,mongodb,express,Javascript,Node.js,Mongodb,Express,我是一个新手,试图创建和运行一个基于nodejs的应用程序 通过nodemon运行server.js时,控制台中出现以下错误 Express server listening on port 3000 Mongoose default connection open to mongodb://localhost:27017/foo GET / 302 18.313 ms - 62 GET / 302 3.115 ms - 62 GET / 302 1.537 ms - 62 GET / 302

我是一个新手,试图创建和运行一个基于nodejs的应用程序

通过nodemon运行server.js时,控制台中出现以下错误

Express server listening on port 3000
Mongoose default connection open to mongodb://localhost:27017/foo
GET / 302 18.313 ms - 62
GET / 302 3.115 ms - 62
GET / 302 1.537 ms - 62
GET / 302 1.480 ms - 62
GET / 302 2.280 ms - 62
GET / 302 0.830 ms - 62
GET / 302 0.835 ms - 62
GET / 302 0.895 ms - 62
下面是我的server.js

var path = require('path');
var bodyParser = require('body-parser');
var cors = require('cors');
var fs = require('fs');
var express = require('express');
var logger = require('morgan');
var mongoose = require('mongoose');
var http = require('http');
//var http = require('follow-redirects').http;

var User = require('./models/User');
var Item = require('./models/Item');
var Menu = require('./models/Menu');
var authController = require('./controllers/auth');
var userController = require('./controllers/user');
var menuController = require('./controllers/menu');
var itemController = require('./controllers/item');
var addressController = require('./controllers/address');
var transactionController = require('./controllers/transaction');
var orderController = require('./controllers/order');
var subscriptionMenuController = require('./controllers/subscription');
var config = require('./config');
var async = require('async');
var bcrypt = require('bcryptjs');


mongoose.connect(config.MONGO_URI);
mongoose.connection.on('error', function (err) {
  console.log('Error: Could not connect to MongoDB. Did you forget to run `mongod`?'.red);
});
// CONNECTION EVENTS
// When successfully connected
mongoose.connection.on('connected', function () {  
  console.log('Mongoose default connection open to ' + config.MONGO_URI);
}); 

// If the connection throws an error
mongoose.connection.on('error',function (err) {  
  console.log('Mongoose default connection error: ' + err);
}); 

// When the connection is disconnected
mongoose.connection.on('disconnected', function () {  
  console.log('Mongoose default connection disconnected'); 
});

// If the Node process ends, close the Mongoose connection 
process.on('SIGINT', function() {  
  mongoose.connection.close(function () { 
    console.log('Mongoose default connection disconnected through app termination'); 
    process.exit(0); 
  }); 
}); 

var app = express();
app.set('port', process.env.PORT || 3000);
app.use(cors());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: true
}));
// Force HTTPS on Heroku
if (app.get('env') === 'production') {
  app.use(function (req, res, next) {
    var protocol = req.get('x-forwarded-proto');
    protocol == 'https' ? next() : res.redirect('https://' + req.hostname + req.url);
  });
}
//app.use(express.static(path.join(__dirname, 'public/dist')));

/*
 |--------------------------------------------------------------------------
 | Log in with Email
 |--------------------------------------------------------------------------
 */
app.post('/auth/login', authController.postLogin);

/*
 |--------------------------------------------------------------------------
 | Create Email and Password Account
 |--------------------------------------------------------------------------
 */
app.post('/auth/signup', authController.postSignup, userController.createUser);

/*
 |--------------------------------------------------------------------------
 | Create Email and Password Account
 |--------------------------------------------------------------------------
 */
app.post('/auth/email', authController.isUserRegistered);

/*
 |--------------------------------------------------------------------------
 | Login with Facebook
 |--------------------------------------------------------------------------
 */
app.post('/auth/facebook', authController.postFacebookLogin);

/*
 |--------------------------------------------------------------------------
 | Unlink Provider
 |--------------------------------------------------------------------------
 */
app.post('/auth/unlink', authController.ensureAuthenticated, authController.postUnlink);

/*
 |--------------------------------------------------------------------------
 | GET /api/me
 |--------------------------------------------------------------------------
 */
app.get('/api/me', authController.ensureAuthenticated, userController.getCurrentUser);

/*
 |--------------------------------------------------------------------------
 | PUT /api/me
 |--------------------------------------------------------------------------
 */
app.put('/api/me', authController.ensureAuthenticated, userController.updateCurrentUser);

/*
 |--------------------------------------------------------------------------
 | GET /api/menus
 |--------------------------------------------------------------------------
 */
app.get('/api/menus', menuController.getMenus);
/*
 |--------------------------------------------------------------------------
 | GET /api/menus
 |--------------------------------------------------------------------------
 */
app.post('/api/menus', menuController.postCreateMenu);

/*
 |--------------------------------------------------------------------------
 | POST /api/items
 |--------------------------------------------------------------------------
 */
app.post('/api/items', authController.ensureAuthenticated, itemController.postCreateItem);

/*
 |--------------------------------------------------------------------------
 | GET /api/items
 |--------------------------------------------------------------------------
 */
app.get('/api/items', authController.ensureAuthenticated, itemController.getItems)

/*
 |--------------------------------------------------------------------------
 | GET /api/items/:id
 |--------------------------------------------------------------------------
 */
app.get('/api/items/:id', authController.ensureAuthenticated, itemController.getItemById)

/*
 |--------------------------------------------------------------------------
 | PUT /api/items
 |--------------------------------------------------------------------------
 */
app.put('/api/items', authController.ensureAuthenticated, itemController.putItems)
/*
 |--------------------------------------------------------------------------
 | POST /api/addresses
 |--------------------------------------------------------------------------
 */
app.post('/api/addresses', authController.ensureAuthenticated, addressController.postCreateAddress);

/*
 |--------------------------------------------------------------------------
 | GET /api/addresses
 |--------------------------------------------------------------------------
 */
app.get('/api/addresses', authController.ensureAuthenticated, addressController.getAddresses)

/*
 |--------------------------------------------------------------------------
 | GET /api/addresses/:id
 |--------------------------------------------------------------------------
 */
app.get('/api/addresses/:id', authController.ensureAuthenticated, addressController.getAddressById)

/*
 |--------------------------------------------------------------------------
 | PUT /api/addresses
 |--------------------------------------------------------------------------
 */
app.put('/api/addresses', authController.ensureAuthenticated, addressController.putAddresses)

/*
 |--------------------------------------------------------------------------
 | POST /api/orders
 |--------------------------------------------------------------------------
 */
app.post('/api/orders', authController.ensureAuthenticated, orderController.postCreateOrder)

/*
 |--------------------------------------------------------------------------
 | GET /api/orders/:id
 |--------------------------------------------------------------------------
 */
app.get('/api/orders/:id', orderController.getOrderById)

/*
 |--------------------------------------------------------------------------
 | GET /api/allorders
 |--------------------------------------------------------------------------
 */
app.get('/api/allorders', orderController.getAllOrders)

/*
 |--------------------------------------------------------------------------
 | GET /api/orders
 |--------------------------------------------------------------------------
 */
app.get('/api/orders',  authController.ensureAuthenticated, orderController.getOrders)

/*
 |--------------------------------------------------------------------------
 | PUT /api/orders/:id
 |--------------------------------------------------------------------------
 */
app.put('/api/orders',  authController.ensureAuthenticated, orderController.putOrders)

/*
 |--------------------------------------------------------------------------
 | POST /api/payumoney
 |--------------------------------------------------------------------------
 */
app.post('/api/pay', authController.ensureAuthenticated, transactionController.postPay);

/*
 |--------------------------------------------------------------------------
 | POST /payment/:id/success
 |--------------------------------------------------------------------------
 */
app.post('/payment/:id/success', transactionController.paymentSuccess)
/*
 |--------------------------------------------------------------------------
 | POST /payment/:id/failed
 |--------------------------------------------------------------------------
 */
app.post('/payment/:id/failed', transactionController.paymentFailed)


/*
 |--------------------------------------------------------------------------
 | POST /api/subscriptions
 |--------------------------------------------------------------------------
 */
app.post('/api/subscriptions', subscriptionMenuController.postCreateSubscriptionMenu) 

/*
 |--------------------------------------------------------------------------
 | GET /api/subscriptions
 |--------------------------------------------------------------------------
 */

app.get('/api/subscriptions', subscriptionMenuController.getSubscriptionMenus) 

/*
 |--------------------------------------------------------------------------
 | GET /api/subscriptions/:id
 |--------------------------------------------------------------------------
 */
app.get('/api/subscriptions/:id', subscriptionMenuController.getSubscriptionMenuById) 

/*
 |--------------------------------------------------------------------------
 | PUT /api/menus
 |--------------------------------------------------------------------------
 */
app.put('/api/subscriptions', subscriptionMenuController.putSubscriptionMenus)
app.get('*', function(req, res) {
  res.redirect('/#' + req.originalUrl);
});

/*
 |--------------------------------------------------------------------------
 | Start the Server
 |--------------------------------------------------------------------------
 */
app.listen(app.get('port'), function () {
  console.log('Express server listening on port ' + app.get('port'));
});
下面是我的config.js文件:-

module.exports = {
  // App Settings
  MONGO_URI: process.env.MONGO_URI || 'mongodb://localhost:27017/foo',
  TOKEN_SECRET: process.env.TOKEN_SECRET || 'YOUR_UNIQUE_JWT_TOKEN_SECRET'
}

302不是错误,而是重定向。你在这里干什么

app.get('*', function(req, res) {
    res.redirect('/#' + req.originalUrl);
});

这将导致一个无休止的循环,除非您在某处处理
/
路由。

看起来您没有配置任何api条目。。。完全没有路由或其他东西可以帮助服务器提供任何其他响应