【发布时间】:2014-09-15 16:48:29
【问题描述】:
对于我的网站,我将所有 assets(字体/图像/js 等)部署到 S3 bucket。 index.html(单页 Ember.js 应用程序)部署在弹性 beanstalk node.js 服务器上。节点app.js 接受对www.domain.com/* 的任何请求,并为本地存储的index.html 提供服务。我希望能够为每个生产构建削减将新应用程序部署到弹性 beanstalk 的过程,只需将所有资产和 index.html 部署到 S3 bucket。
这是我目前所拥有的:
var AWS = require('aws-sdk'),
fs = require('fs');
/*
* AWS Security credentials
*/
AWS.config.loadFromPath('./config.json');
var port = process.env.PORT || 3000,
http = require("http");
var static = require('node-static');
/*
* Create a node-static server instance
* to serve the './public' folder
*/
var file = new static.Server();
/*
* Fetch .index.html from S3
* and cache it locally
*/
var s3 = new AWS.S3();
var params = {Bucket: 'assets', Key: 'index.html'};
var file = fs.createWriteStream('index.html');
s3.getObject(params).
on('httpData', function(chunk) { file.write(chunk); }).
on('httpDone', function() { file.end(); }).
send();
var server = http.createServer(function (request, response) {
request.addListener('end', function () {
file.serveFile('index.html', 200, {}, request, response);
}).resume();
}).listen(port);
我假设这只会在服务器首次启动时从 S3 获得index.html。缓存的最佳做法是什么,最好是 1 分钟到期。
谢谢!
【问题讨论】:
标签: node.js amazon-web-services ember.js amazon-s3 ember-cli