如何从s3到节点expressjs服务静态网站? [英] How can I serve static web site from s3 through node expressjs?

查看:62
本文介绍了如何从s3到节点expressjs服务静态网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我使用app.use(express.static('public')),并且我的文件位于我的node js express应用程序的公用文件夹中,并且工作正常. 但是,我想将这些文件(index.html等)存储在我的s3存储桶中(以便多个应用程序可以使用此网站). 我尝试过

currently I use app.use(express.static('public')) and my files located in the public folder of my node js express app and its working good. However, I would like to store those files (index.html, etc) in my s3 bucket (so multiple apps can use this website). I tried

app.get('/', function(req, res) {
    res.sendfile('link-to-s3-file/index.html'); 
 });

没有成功...

推荐答案

我不会重新发明轮子.在 npm

I wouldn't reinvent the wheel. There's a reasonably recent and well documented middleware module for this on npm

从文档中

app.get('/media/*', s3Proxy({
  bucket: 'bucket_name',
  prefix: 'optional_s3_path_prefix',
  accessKeyId: 'aws_access_key_id',
  secretAccessKey: 'aws_secret_access_key',
  overrideCacheControl: 'max-age=100000'
}));

这篇关于如何从s3到节点expressjs服务静态网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆