1

当我使用 ng serve 启动开发节点服务器时。并输入下面的地址,它的工作原理。

http://localhost:4200/login       

但是,当我输入我的用户名和密码时,它会在控制台中显示以下错误。

 OPTIONS http://localhost:3000/api/findCoinData?_id=5a1b2d9a6e915f5838ae5a50 
 net::ERR_CONNECTION_REFUSED

我努力了

 ng serve --host 0.0.0.0

 ng serve --port 8080 --host 0.0.0.0 --disableHostCheck true 

一直出现同样的错误,我感觉这个问题是由于 localhost 设置造成的,但是将其更改为本地 IP 并没有解决问题。

有人知道这里可能出了什么问题吗?

我使用时一切正常:

npm start

应用程序.js

 var express = require('express');
 var path = require('path');
 var favicon = require('serve-favicon');
 var logger = require('morgan');
 var cookieParser = require ('cookie-parser');
 var session = require ('express-session');
 var bodyParser = require('body-parser');
 var morgan = require ('morgan');
 var mongo= require('mongodb');


 var mongoose = require('mongoose');
 var flash = require('connect-flash');
 var chat = require('./server/routes/chat');
 var connect = require('./models/user')
  //var cors = require('cors');
  connect.connect('mongodb://localhost/loginapp');
 var db = mongoose.connection;

  var passport = require ('passport');
  //var LocalStrategy = require ('passport-local').LocalStrategy;

   var Schema = mongoose.Schema;


  var config = require ('./config/database');
 var engines = require('consolidate');


 var router = express.Router();
 var api = require('./server/routes/api');
 var app = express();
 app.use(logger('dev'));
 //app.use(cors());

// directories that are publicly accesible through the browser.
app.use(express.static(path.join(__dirname, 'dist')));
app.use(express.static(path.join(__dirname, 'public')));

 app.use(cookieParser());
 app.use(morgan('dev'));
 app.use(session({
secret: 'secret123',
resave: true,
  saveUnitialized: true
  }));

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

 //initialise always before session!
 app.use(passport.initialize());
 app.use(passport.session());
 app.use(flash());
 //set viewing engine

 app.use('/api', api);
 //app.get("/test", findAllMessages);
 app.get('*', (req, res) => {

res.sendFile(path.join(__dirname, 'dist/index.html'));


   });

 // global variables flash
   app.use(function(req,res, next) {
res.locals.succes_msg = req.flash('succes_msg');
res.locals.error_msg = req.flash('error_msg');
    res.locals.error = req.flash('error');
res.locals.user = req.user || null;
next();
    });


   module.exports = app;
4

0 回答 0