I created a Web Application using AngularJS x ExpressJS where GET "/" of my app.js renders the index.html of the application.
For example, I have GET /test-data on my app.js and trying to fetch those test data from AngularJS via localhost:port/test-data. While this is working on my test environment, I always had to alter the request URL on production to production's REST.
Is there any way that I can prevent the problem stated above editing the URL during deployment?
Sample codes:
(app.js)
var express = require("express");
var app = express();
var request = require("request");
var port = 3000;
var bodyParser = require("body-parser");
app.use(express.static(__dirname));
app.use(bodyParser.json());
app.get("/", function(request, response) {
response.sendFile(__dirname + "/index.html");
});
app.get("/test-data", function(req, res, next) {
var returnValue = [
{
username : "MAIK",
fullname : "Michael"
},
{
username : "CLARK",
fullname : "Clark"
},
{
username : "ROLLY",
fullname : "Roland"
},
{
username : "FLOYDIE",
fullname : "Floyd"
},
{
username : "ZOE",
fullname : "Zoe"
}
];
res.send(returnValue);
});
app.listen(port, function() {
console.log("Listening to port " + port + "...");
});
(MySampleService.js)
.service("MySampleService", function($http) {
this.sampleURL = "localhost:3000";
this.getTestData= function(){
return $http
(
{
method : "GET",
url : "http://" + this.sampleURL + "/test-data
}
);
};
});