forked from ajyounguk/aws-sqs-sns-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
86 lines (63 loc) · 2.3 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// setup express server
var express = require('express');
var aws = require('aws-sdk');
var fs = require('fs');
var app = express();
// load aws config
aws.config.loadFromPath(__dirname + '/config/aws-config.json')
// load and override endpoints (if config file exists)
var configFile = null
try {
configFile = fs.readFileSync(__dirname + '/config/aws-override.json','utf8');
} catch (err) {
if (err.code === 'ENOENT') {
console.log("No local AWS endpoint config found, using dafault routing to AWS")
} else {
throw(err)
}
}
// if found, parse override config
if (configFile) {
overrides = JSON.parse(configFile)
console.log('Overriding AWS SQS endpoint to:', overrides.sqs_endpoint)
console.log('Overriding AWS SNS endpoint to:', overrides.sns_endpoint)
aws.config.sqs = { 'endpoint': overrides.sqs_endpoint }
aws.config.sns = { 'endpoint': overrides.sns_endpoint }
}
// this is the main object for holding all the UI data rendered in ejs templates
// date for the various UI menu items is held in the 'data' array.
//
// menuitem is used to hold the currently active / selected menu items to be displayed,
// when index.ejs is loaded, it invokes a javascript function to enable the required div section using
// this variable.
//
// the def_* variables are used to hold default / prepop values for the various input boxes
var ui = {
menuitem: 1,
data: [],
def_snsname: '',
def_snsarn: '',
def_sqsname: '',
def_sqsurl: '',
def_sqsar: '',
def_subarn: '',
def_msghandle: ''
}
var snsController = require('./controllers/snsController')
var sqsController = require('./controllers/sqsController')
snsController(aws, app, ui);
sqsController(aws, app, ui);
// server listen port - can be overriden by an environment variable
var port = process.env.PORT || 3000
// configure assets and views
app.use('/assets', express.static(__dirname+'/public'))
app.set('views', __dirname+'/views');
app.set('view engine', 'ejs')
// login and serve up index
app.get('/', function (req, res) {
res.setHeader('Content-Type', 'text/html');
res.render('./index', {ui: ui})
})
// Start server.
app.listen(port)
console.log('AWS SNS SQS test server listening on port', port);