diff --git a/README.md b/README.md index 3d2a490a25..ea86bb2d88 100644 --- a/README.md +++ b/README.md @@ -82,5 +82,13 @@ To generate your Alfresco Angular 2 application you can use the following Yeoman - [Yeoman Generator Angular 2 Alfresco application](https://github.com/Alfresco/generator-ng2-alfresco-app) +## Amazon AWS Elastic Beanstalk fast deploy +

+ AmazonWebservices Logo.svg +

+ +To deploy directly on your AWS instance our demo shell click the button below: + + diff --git a/demo-shell-ng2/.ebextensions/deploy_npm.config b/demo-shell-ng2/.ebextensions/deploy_npm.config new file mode 100644 index 0000000000..7abdb9c83f --- /dev/null +++ b/demo-shell-ng2/.ebextensions/deploy_npm.config @@ -0,0 +1,18 @@ +files: + "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh" : + mode: "000775" + owner: root + group: root + content: | + #!/bin/bash + function error_exit + { + eventHelper.py --msg "$1" --severity ERROR + exit $2 + } + + export HOME=/home/ec2-user + echo "export home" + + sudo curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash - + sudo yum install -y nodejs diff --git a/demo-shell-ng2/app.js b/demo-shell-ng2/app.js new file mode 100644 index 0000000000..f897a59bcc --- /dev/null +++ b/demo-shell-ng2/app.js @@ -0,0 +1,77 @@ +var port = process.env.PORT || 3000, + http = require('http'), + fs = require('fs'), + url = require('url'), + mime = require('mime'), + html = fs.readFileSync('index.html'); + +var log = function(entry) { + fs.appendFileSync('/tmp/sample-app.log', new Date().toISOString() + ' - ' + entry + '\n'); +}; + +var server = http.createServer(function (req, res) { + + // Parse the request containing file name + var pathname = url.parse(req.url).pathname; + + // Print the name of the file for which request is made. + console.log("Request for " + pathname + " received."); + + if (req.method === 'POST') { + var body = ''; + + req.on('data', function(chunk) { + body += chunk; + }); + + req.on('end', function() { + if (req.url === '/') { + log('Received message: ' + body); + } else if (req.url = '/scheduled') { + log('Received task ' + req.headers['x-aws-sqsd-taskname'] + ' scheduled at ' + req.headers['x-aws-sqsd-scheduled-at']); + } + + res.writeHead(200, 'OK', {'Content-Type': 'text/plain'}); + res.end(); + }); + } else { + var filename = pathname.substr(1); + if(filename === '' || filename.indexOf('.') === -1){ + filename = 'index.html'; + } + // Read the requested file content from file system + fs.readFile(filename, function (err, data) { + if (err) { + console.log(err, filename); + // HTTP Status: 404 : NOT FOUND + // Content Type: text/plain + res.writeHead(404, {'Content-Type': 'text/html'}); + }else{ + //Page found + // HTTP Status: 200 : OK + // Content Type: text/plain + var type = mime.lookup(filename); + console.log('type',type); + if (!res.getHeader('content-type')) { + var charset = mime.charsets.lookup(type); + res.setHeader('Content-Type', type + (charset ? '; charset=' + charset : '')); + } + if(type.indexOf('image') > -1 || type.indexOf('font') > -1){ + var img = fs.readFileSync(pathname.substr(1)); + res.end(img, 'binary'); + }else{ + res.write(data.toString()); + } + // Write the content of the file to response body + } + // Send the response body + res.end(); + }); + } +}); + +// Listen on port 3000, IP defaults to 127.0.0.1 +server.listen(port); + +// Put a friendly message on the terminal +console.log('Server running at http://127.0.0.1:' + port + '/'); diff --git a/demo-shell-ng2/package.json b/demo-shell-ng2/package.json index 117fed496f..1a50ffdb5a 100644 --- a/demo-shell-ng2/package.json +++ b/demo-shell-ng2/package.json @@ -7,6 +7,7 @@ "postinstall": "typings install", "clean": "rimraf node_modules typings", "start": "npm run tslint && concurrently \"npm run tsc:w\" \"license-check\" \"npm run serve\" ", + "aws": "node app.js", "tsc": "tsc", "tsc:w": "tsc -w", "serve": "wsrv -o -s -l -p 3000 -a 0.0.0.0 -x ./server/versions.js", @@ -66,14 +67,12 @@ "reflect-metadata": "0.1.3", "rxjs": "5.0.0-beta.6", "zone.js": "0.6.12", - "rimraf": "2.5.2", "material-design-icons": "2.2.3", "material-design-lite": "1.1.3", "ng2-translate": "2.2.0", "pdfjs-dist": "1.5.258", "flag-icon-css": "2.3.0", - "alfresco-js-api": "0.2.1", "ng2-alfresco-core": "0.2.0", "ng2-alfresco-datatable": "0.2.0", @@ -89,6 +88,7 @@ "devDependencies": { "concurrently": "2.0.0", "license-check": "1.1.5", + "mime": "^1.3.4", "tslint": "3.8.1", "typescript": "1.8.10", "typings": "1.0.4",