admin管理员组文章数量:1418140
I recently deployed my Node.js blog on AppFog. I plan to use a bucket on Amazon S3 to stream my assets (javascript/stylesheets/images).
How can I make sure that Express.js get static assets to my Amazon S3 bucket instead of the regular /public
?
I recently deployed my Node.js blog on AppFog. I plan to use a bucket on Amazon S3 to stream my assets (javascript/stylesheets/images).
How can I make sure that Express.js get static assets to my Amazon S3 bucket instead of the regular /public
?
- Why not just make the bucket public and and link directly to the assets on //s3.amazonaws./bucketname/filename.ext? – josh3736 Commented Feb 7, 2013 at 3:34
- What do you mean? I'm migrating my old sites with url like /images/2012/... I cannot change the path. – jpmonette Commented Feb 7, 2013 at 3:36
- I've added an answer that expands on what I mean. Why can't you change the path? – josh3736 Commented Feb 7, 2013 at 3:53
2 Answers
Reset to default 8I wouldn't stream assets through the node server – it's a waste of resources, and you're going to have to deal with HTTP caching headers.
Instead, your HTML should link directly to the S3 bucket. Instead of:
<script src="/js/script.js"></script>
Do:
<script src="//s3.amazonaws./bucket/js/script.js"></script>
Given that you're migrating, just set up a permanent redirect.
app.get(/^\/(js|css|images)\/.*/, function(req, res) {
res.redirect(301, '//s3.amazonaws./bucket' + req.path);
});
This will redirect all requests for things in the js, css, and images folders to a S3 bucket. For example, /js/script.js would redirect to //s3.amazonaws./bucket/js/script.js.
This will help ease the transition, but you should still migrate your site's references to the S3 URLs to eliminate the unnecessary HTTP roundtrip cause by having the redirect.
If you really need to do this, use pipe() from the request library: https://github./mikeal/request#streaming
本文标签: javascriptStreaming Assets (JSCSSimages) from Amazon S3 with ExpressjsStack Overflow
版权声明:本文标题:javascript - Streaming Assets (JSCSSimages) from Amazon S3 with Express.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745279452a2651353.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论