forked from ajyounguk/aws-sqs-sns-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
74 lines (54 loc) · 2.02 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
// setup express server
var express = require('express');
var aws = require('aws-sdk');
var fs = require('fs');
var app = express();
//By default, AWS SDK will read environment variables to configure AWS credentials.
//Optional - override default SNS/SQS endpoints
var sns_endpoint_override = process.env.SNS_ENDPOINT;
var sqs_endpoint_override = process.env.SQS_ENDPOINT;
if(!!sns_endpoint_override){
console.log('Overriding AWS SNS endpoint to:', sns_endpoint_override)
aws.config.sns = { 'endpoint': sns_endpoint_override }
}
if(!!sqs_endpoint_override){
console.log('Overriding AWS SQS endpoint to:', sqs_endpoint_override)
aws.config.sqs = { 'endpoint': sqs_endpoint_override }
}
// 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);