3

I want to deploy CRA bundles to s3 and serve from cloudfront. But index file should be express view (template, I want to add some data to it). All solutions I've found assume serverless or serve CRA index directly from node.

So, I need index to be template and contain cloudfront URLs to bundles. How can I achieve this?

Mykyta Shyrin
  • 312
  • 1
  • 14
  • Are you saying that you want your index.html file to be dynamic? Meaning you might add some data to it during runtime? What data would you inject to it? Is it just the cloudfront URLs? – Jackyef Dec 22 '19 at 04:31
  • #1 s3 and cloudfront are two different platforms. #2 if you need to create dynamically the index.html you need a backend language (nodejs express) or using react create a dynamic page. #3 You have two questions here. What is your requirement? – JRichardsz Dec 22 '19 at 15:53
  • I have node/express server. I want it to serve index.html (to add some context) and APIs. But I don't want it to serve statics (first of all, bundles). So, use cloudfront to serve bundle files, but have express app able to respond with index.html correctly referencing script files – Mykyta Shyrin Dec 24 '19 at 11:45

1 Answers1

1

If you need to create and index.html you could do that without template

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

Or with templates like

Jade

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..

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

Pug

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!'});
});
JRichardsz
  • 14,356
  • 6
  • 59
  • 94
  • @mykyta-shyrin if this helped to solve your problem or question, please use the checkmark on the left to mark this as solved. – JRichardsz Dec 27 '19 at 18:08