【问题标题】:Deploy CRA to s3 and serve with express将 CRA 部署到 s3 并使用 express 服务
【发布时间】:2020-04-11 05:12:38
【问题描述】:

我想将 CRA 包部署到 s3 并从云端提供服务。但是索引文件应该是快速视图(模板,我想向它添加一些数据)。我发现的所有解决方案都假定无服务器或直接从节点提供 CRA 索引。

因此,我需要将索引作为模板并包含捆绑包的云端 URL。我怎样才能做到这一点?

【问题讨论】:

  • 你是说你希望你的 index.html 文件是动态的吗?这意味着您可能会在运行时向其添加一些数据?你会向它注入什么数据?只是云端 URL 吗?
  • #1 s3 和 cloudfront 是两个不同的平台。 #2 如果您需要动态创建 index.html,则需要后端语言(nodejs express)或使用 react 创建动态页面。 #3 你有两个问题。你有什么要求?
  • 我有节点/快递服务器。我希望它为 index.html (添加一些上下文)和 API 提供服务。但我不希望它提供静态(首先是捆绑)。因此,请使用 cloudfront 来提供捆绑文件,但让 express 应用程序能够使用 index.html 正确引用脚本文件来响应

标签: reactjs express amazon-cloudfront devops create-react-app


【解决方案1】:

如果您需要创建 index.html,您可以在没有模板的情况下这样做

app.get('/', function(req, res) {
  res.type('text/html');
  res.send('<html>...</html>');
});

或者使用类似的模板

翡翠

doctype html
html
    head
        title Jade Page
        link(href='https://cloudf../css/main.css', rel='stylesheet')
    body
        h1 This page is produced by Jade engine
        p some paragraph here..

来源:https://www.tutorialsteacher.com/nodejs/jade-template-engine

帕格

html
   head
   title= title
   link(href='https://cloudf../css/main.css' rel='stylesheet')                                                                                                                       
body
   h1= message

app.get('/', function (req, res) {
    res.render('index', { title: 'Hey', message: 'Hello there!'});
});

【讨论】:

  • @mykyta-shyrin 如果这有助于解决您的问题或疑问,请使用左侧的复选标记将其标记为已解决。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-09
  • 2020-10-07
  • 1970-01-01
  • 1970-01-01
  • 2021-08-07
  • 2021-06-22
  • 1970-01-01
相关资源
最近更新 更多