问题
I am working with amazon aws server and writing an application to access my instances. But I am not able to pass around the amazon global config variable to the javascript file that gets executed when the button is clicked.
This is my structure --
app.js -.
var express = require('express')
, http = require('http')
, us = require('underscore')
, aws = require('aws-sdk')
, fs = require('fs');
....
var contents = fs.readFileSync("aws_config/LAUNCH.config.json");
var launch_config = JSON.parse(contents);
var contents = fs.readFileSync("aws_config/AWS_CREDENTIALS.config.json");
var aws_config = JSON.parse(contents);
aws.config.update({
accessKeyId: aws_config.accessKeyId,
secretAccessKey: aws_config.secretAccessKey,
region: aws_config.region
});
...
app.get('/', function(req, res){
res.render("index.jade",{aws_config_file : aws_config,
launch_config_file : launch_config,
aws_var : aws});
});
...
This the point where I show some HTML in the index page and and have an form with button which gets the status of the instance from the server. So
index.jade
p.buttons
input(type = "button", style='value = 'Check' , onclick = "t(aws_config_file,launch_config_file,aws_var)")
Now in my t() function in another file I use the amazon API ..
t(aws_config_file,launch_config_file,aws) {
**var ec2 = new aws.EC2();**
**var autoscaling = new aws.AutoScaling();**
perform the check.. call the aws call back provided in the API.
}
How can I use the aws variable that I defined in the app.js file in the function t(). I tried declaring the aws variable in function t .. even that does not work.
Can someone help.
Thanks
来源:https://stackoverflow.com/questions/17843787/using-global-config-variable-in-express-node-js-framework