2

I ran into issues on calling a Express route from my Angular template route and Express -> Angular. This code shows my attempt into tackling this issue.

// Server.js file, the main Node.js code

var Outlook = require('Outlook');

// Bootstrap db connection
var db = mongoose.connect(config.db, function(err) {
  etc..
});

// Init the express application
var app = require('./config/express')(db);

app.listen('8443'); // Main server.

// App.js - The Outlook module Express route example code

var app = require('express');
var app = express();
// Configure express
// Set up rendering of static files

app.use(express.static('static'));
// Need JSON body parser for most API responses
app.use(bodyParser.json());
// Set up cookies and sessions to save tokens
app.use(cookieParser());

  // Home page
  app.get('/', function(req, res) {
    res.send(pages.loginPage(authHelper.getAuthUrl()));
  });

  app.get('/express', function(req, res) {
    console.log(req.params.msg);
    return 'Your EXPRESS DATA IS HERE!';
  });

app.listen(3000); // Is this really necessary? 

// outlook.cliet.routes.js

'use strict';

//Setting up route
angular.module('outlook').config(['$stateProvider', '$http',

    function($http) {
        $http.get('http://localhost:3000/express',{"msg":"hi"}).success(function(data){
        console.log(data);
    });

]);

Issue 1: I don't want to make express run two different servers in different ports in the same instance. That lead me to next issue.

I am using oauth-sign and simple-oauth2 when I bounce back from the outlook module to the main express server, I am logged off the main server.

I don't think it is required a separate express server. Is it possible to make app.js express routing work without listening to a second express server? Notice that express is initialized in a different way. Perhaps module.exports could help?

Thanks

staminna
  • 468
  • 1
  • 5
  • 26
  • If you want to serve angular HTML from a different port within an application, you can use specific gulp task for it. – Sridhar Jan 05 '17 at 01:34
  • The problem at the moment is that I can't comunicate between two Express servers on different ports. – staminna Jan 05 '17 at 18:13
  • This seems to be relevant. The user runs the app on two different ports. http://stackoverflow.com/a/28755809/978501 – Sridhar Jan 06 '17 at 01:51
  • Yes but the example runs on the same module file, not on different modules. Also the user would be logged out from the main Express session. Read Issue 1 and 2 in the end. Thanks Sridhar for your effort so far – staminna Jan 06 '17 at 13:59

0 Answers0