1

When I start the development Node server with ng serve. and type in the below address, it works.

http://localhost:4200/login       

However when I type in my username and password it gives me the below error in the console.

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

I have tried

 ng serve --host 0.0.0.0

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

Keep getting the same error, I have a feeling this problem happens due to the localhost setting, but changing it to the local IP didn't solve the issue.

Anyone has any idea what could be going wrong here?

All works when I use:

npm start

app.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;
oudekaas
  • 325
  • 1
  • 6
  • 21

0 Answers0