0

I have project build on top of create-react-app. Now, i want deploy with KoaJS. This is my code: server.js

const serve = require('koa-static');
const logger = require('koa-logger');
const Koa = require('koa');
const app = new Koa();
const port = process.env.SERVER_PORT;

app.use(logger());
app.use(serve(__dirname + '/build'));

app.listen(port);
console.log(`Kylin listening ${process.env.SERVER_ENV} on port ${port}`);

When i build, deploy and visit index (path: "/"), everything ok. But, when i visit another route, ex: /about, server response "Not found". What wrong? Somebody can help me plz!!!!

Dean
  • 415
  • 1
  • 5
  • 15

1 Answers1

1

See https://stackoverflow.com/a/52462348/9341118

If you are using react-router, you can add middleware to whitelist the client routes and rewrite the paths to '/', which will force index.html and all the client assets to load on a full page get or refresh, while allowing react router to parse the original request path (e.g. /about).