/
index.js
49 lines (34 loc) · 1.24 KB
/
index.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
// Created by: Matthew Trotter C.E.O www.SudirlayCoders.com licensed @sudirlaycoders.com 2017
// Submission of post body params are in consistency with the rules of nodejs Amazon Web Services SDK for route53
const express = require('express');
const fs = require('fs');
const app = express();
const bodyparser = require('body-parser');
// AWS Required
const AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';
AWS.config.apiVersions = {
route53domains: '2014-05-15',
};
app.use(bodyparser.urlencoded({extended: true}));
app.use(bodyparser.json());
app.get('/', function(req, res){
console.log('GET /')
const html = fs.readFileSync('index.html');
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(html);
});
app.post('/', function(req, res){
console.log('POST /');
console.dir(req.body);
const route53domains = new AWS.Route53Domains();
res.writeHead(200, {'Content-Type': 'text/html'});
const params = req.body;
route53domains.checkDomainAvailability(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else res.end('This Domain is: ' + data.Availability);
})
});
port = 8135;
app.listen(port);
console.log('awsdomainchecker listening at http://localhost:' + port)