under construction, the html5 page"s html prints instead of displaying

This commit is contained in:
Anton Georgiev 2014-05-13 19:43:47 +00:00
parent 69b9ec6493
commit f76fedee6a
4 changed files with 66 additions and 20 deletions

View File

@ -30,6 +30,23 @@ app.configure ->
app.use express.methodOverride()
app.use express.cookieParser()
# Enables CORS
enableCORS = (req, res, next) ->
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With')
# intercept OPTIONS method
if ('OPTIONS' is req.method)
res.send(200)
else
next()
# enable CORS!
app.use(enableCORS)
# redis
app.use express.session(
secret: config.app.sessionSecret

View File

@ -11,32 +11,53 @@ app.set('port', config.settings.PORT)
app.set('views', '/views')
cors = require('cors')
###cors = require('cors')
corsOptions = {
origin: 'http://google.com'
}
app.use(cors())###
###enableCORS = (req, res, next) ->
console.log "jjj"
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
#intercept OPTIONS method
if ('OPTIONS' == req.method)
console.log "ppp"
res.send(200);
else
console.log "qqq"
next()
# enable CORS!
app.use(enableCORS)###
app.post('/loginnn', (req, res) ->
console.log "i am in POST loginnn"
console.log "req = " + JSON.stringify req.body
#res.json({"a": "b"})
res.redirect('http://192.168.0.203:3000/')
)
app.get('/', handlers.index)
app.post('/login', cors(corsOptions), handlers.login)
app.post('/login', handlers.login)
http.createServer(app).listen(app.get('port'), () ->
console.log('Express server listening on port ' + app.get('port'))
console.log('Express server listening on port ' + app.get('port'))
)
app.get "/*", (req, res, next) ->
app.get("/*", (req, res, next) ->
file = req.params[0]
console.log "\t :: Express :: file requested : " + file
#Send the requesting client the file.
res.sendfile __dirname + "/" + file
if file is "public/js/app.js" or file is "config.json"
#Send the requesting client the file.
res.sendfile __dirname + "/" + file
next
)

View File

@ -7,6 +7,8 @@ index = (request, response) ->
response.sendfile('./views/index.html')
login = (req, resp) ->
###resp.header("Access-Control-Allow-Origin", "*")
resp.header("Access-Control-Allow-Headers", "X-Requested-With")###
createParams = testapi.createParams
joinParams = testapi.joinParams
@ -52,15 +54,11 @@ login = (req, resp) ->
else
console.log("----")###
url = "http:/192.168.0.203/html5.client?meeting_id=" + meeting_id + "&user_id=" + user_id + "&auth_token=" + auth_token
resp.redirect(url) #trying to use the "cors" npm module
###resp.redirect("http:/192.168.0.203/html5.client?meeting_id=" + meeting_id +
"&user_id=" + user_id + "&auth_token=" + auth_token)###
resp.redirect("http://google.com") #trying to use the "cors" npm module
console.log ("I am done for now "+ req.xhr)
console.log ("I am done for now "+ req.xhr)
)
)

View File

@ -3,13 +3,23 @@ var myModule = angular.module('landingPage', []);
myModule.controller('MainCtrl', function($scope, $http) {
$scope.blah = {
name: 'zZzZ',
password: 'oOoOoO'
};
$scope.postUsername = function(username) {
console.log("the passed uname=" + this.username);
jQuery.getJSON("config.json", function (json) {
/*jQuery.getJSON("config.json", function (json) {
$http.post(json.settings.IP + ':' + json.settings.PORT + '/login?username=' +
$scope.username).success(function(res){
console.log("SUCCESS," + res /*JSON.stringify(res)*/); //does not print
console.log("SUCCESS," + JSON.stringify(res));
});
}); */
$http.post('loginnn', $scope.blah).success(function(res){
console.log("SUCCESS," + JSON.stringify(res));
var newWindow = window.open("", "newWindow", "resizable=yes");
newWindow.document.write('JSON.stringify(res)');
});
}
});