简体   繁体   English

http://localhost:3000/api/users net::ERR_CONNECTION_REFUSED

[英]http://localhost:3000/api/users net::ERR_CONNECTION_REFUSED

I can login to my app and it shows that login is successful, however when I refresh page it gives this error我可以登录我的应用程序并显示登录成功,但是当我刷新页面时出现此错误

http://localhost:3000/api/users net::ERR_CONNECTION_REFUSED

I'm using Node.js with Angular on front.我在前面使用 Node.js 和 Angular。 Also using JWT for tokens.还使用 JWT 作为令牌。

My backend app.js:我的后端 app.js:

    app.use(morgan('dev'));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(cookieParser());

mongoose.connect(config.database);

app.use(cors({origin: "http://localhost:8000",credentials: true }));

app.use('/api/upload/single', expressJWT({secret: config.secret}));



app.use(function (error, request, response, next) {   if (error.name === 'UnauthorizedError') {
    response.status(401).json({message: 'You need an authorization token to view this page.'});   } });

// MULTER var s3config = require('./config/s3'); var upload = multer({ storage: s3({
    dirname: s3config.dirname,
    bucket: s3config.bucket,
    secretAccessKey: process.env.AWS_ACCESS_SECRET,
    accessKeyId: process.env.AWS_ACCESS_KEY,
    region: s3config.region,
    contentType: function(req, file, next) {
      next(null, file.mimetype);
    },
    filename: function(req, file, next) {
      var ext = '.' + file.originalname.split('.').splice(-1)[0];
      var filename = uuid.v1() + ext;
      next(null, filename);
    }   }) });

// UPLOAD SINGLE FILE app.post('/api/upload/single', upload.single('file'), function(req, res) {   var clothing_1 = {
    type: req.body.type,
    image: req.file.key   };   console.log(req.body);   // get the user model User.findOne({ id: req.user._id })   User.findOne({ _id: req.user._id }, {}, { new: true }, function(err, user){
    user.clothing.push(clothing_1);
    // save this user
    user.save(function(err, user){
      if(err) return res.status(401).send({ message: 'your error:' + err });
      else return res.json({ user: user })
    });   });

}); // app.get('api/users', usersController.showUser); app.use('/api', routes);

app.listen(3000);

结果证明只是没有在我的 Angular 状态上放置正确的控制器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 节点:VM12:1 POST http://localhost:3000/auth net::ERR_CONNECTION_REFUSED - Node: VM12:1 POST http://localhost:3000/auth net::ERR_CONNECTION_REFUSED 加载资源失败:.net::ERR_CONNECTION_REFUSED http://127.0.0.1:3000/api/categories - Failed to load resource: net::ERR_CONNECTION_REFUSED http://127.0.0.1:3000/api/categories POST http://localhost:9000/ net::ERR_CONNECTION_REFUSED - POST http://localhost:9000/ net::ERR_CONNECTION_REFUSED POST http://localhost:3001/send net::ERR_CONNECTION_REFUSED - POST http://localhost:3001/send net::ERR_CONNECTION_REFUSED 选项 http://localhost:3800/ net::ERR_CONNECTION_REFUSED - OPTIONS http://localhost:3800/ net::ERR_CONNECTION_REFUSED 向“http://localhost:3000/”发出 GET 请求时出错“加载资源失败:net::ERR_CONNECTION_REFUSED ... delete.js” - error when making GET request to 'http://localhost:3000/' “Failed to load resource: net::ERR_CONNECTION_REFUSED … delete.js” ERR_CONNECTION_REFUSED http://localhost:3000/socket.io/socket.io.js - ERR_CONNECTION_REFUSED http://localhost:3000/socket.io/socket.io.js Web3.js - 选项 http://localhost:8545/net::ERR_CONNECTION_REFUSED - Web3.js - OPTIONS http://localhost:8545/ net::ERR_CONNECTION_REFUSED 保险丝盒导致GET http:// localhost:4444 / net :: ERR_CONNECTION_REFUSED - fuse-box caused GET http://localhost:4444/ net::ERR_CONNECTION_REFUSED 无法从 Javascript net::ERR_CONNECTION_REFUSED 访问 localhost - Cannot access localhost from Javascript net::ERR_CONNECTION_REFUSED
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM