lundi 22 août 2016

Putting Nodejs onto a website

So I have a web app that communicates to a nodejs server. What I am trying to do is allow access to my nodejs server from anywhere not just localhost. Instead of posting to 'localhost:8080' in my app i would like to post to my own url like 'http://(insert url here).com/push' to connect to my nodejs server. Can anyone help me figure this out? Ive done my research and yet I can't seem to find what I need to do.

I'll post my code even though it really isn't needed:

app.controller('myCtrl', function($scope, $rootScope, $http) {
    var isAndroid = ionic.Platform.isAndroid();
    var isios = ionic.Platform.isIOS();
    var fName = $rootScope.fName;
    var lName = $rootScope.lName;
    var messageText = $rootScope.messageText;
    var token = $rootScope.devToken;
    var selectedUser = $rootScope.selectUser;
    
    $scope.submit = function() {
        $http.post('http://url here', {firstName: fName, lastName: lName, message: messageText, token: token, isAndroid: isAndroid, isios: isios, selectedUser: selectedUser});
        $rootScope.messageText = "";
    }
    
})
app.post('/', function(req, res) {
    firstName = req.body.firstName;
    lastName = req.body.lastName;
    message = req.body.message;
    token = req.body.token;
    user = {name: firstName + " " + lastName, token: token};
    selectedUser = req.body.selectedUser;
    users.push(user);
    
    if (req.body.isAndroid === true) {
        sendToAndroid();
    } else {
        sendToios(); 
    }
});



app.listen(8080, function() {
    console.log('running on port 8080');
});

Aucun commentaire:

Enregistrer un commentaire