0

I have React app. I have bundle.js and index.html with scripts and a root element. How I can send it from the server?

I have a Koa.js server

const Koa = require('koa');
const app = new Koa();

app.use(async ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

Can I send index.html as a static file, or does react have another way?

cyber-leech
  • 37
  • 2
  • 2
  • 9
user10053586
  • 79
  • 2
  • 7
  • Possible duplicate of [Koa.js - serving static files and REST API](https://stackoverflow.com/questions/32721311/koa-js-serving-static-files-and-rest-api) – Blue Mar 08 '19 at 10:50

1 Answers1

1

It's easy. You need to install koa-static. Also have a folder for your static files, for example public, you need to have your reactjs app build there. Then add koa-static middleware to your server, here's a gist of it:

const Koa = require('koa')
const serve = require('koa-static')

const app = new Koa();
app.use(serve(__dirname + '/public'))

app.listen(3000)
Anton Harniakou
  • 855
  • 6
  • 13