Having completed my project, now when it comes to deployment, I’m having issues serving CRA’s build folder.
// server.ts
const app = express();
app.use(express.static(path.join(__dirname, 'pathToBuild')));
app.use(routes).
// ...
This files bundles all of the Routers inside of one, resulting in the one being used inside of server.ts
.
// routes.ts
const router = Router();
router.use("/users", usersRouter);
router.use("/auth", authRouter);
router.use("/*", (req, res) => {
res.sendFile(pathRelativeToBuildIndexHtml)
})
Example of the /users
router:
// usersRouter.ts
const router = Router();
router.route("/").get(usersFetch);
router.route("/:id").get(userFetch).patch(userEdit).delete(userDelete);
The only routes that are getting served the static files are:
/
/*
I’m thinking it’s something about the index Router wrapping other Routers. That’s all I can think of at the moment.