Monday 13 November 2017

Serving React (sub) app on a specific route with Express

Well, I was wondering what's the best way to manage sub apps with express? For example, I'm trying to make a web application / site with administration panel and I wanted a panel to be a completely independent app (with it's client side framework like react, libraries, static files and so on) from which I'll be able to control main app (app that's being serverd on root route). Root route app has nothing to with react and stuff.So I was thinking about creating a route for my panel app, something like /panel or /admin and serving a react app on that route. Problem is I don't know how to do it properly, I mean I started something but I wanna be sure in the start that I am doing the right thing.EDIT: (well, that was quick)I found something like this on a blog. I think it suits my needs.var express = require("express"); // sub-apps var sub1 = express(); sub1.get("/", function(req, res){ res.json({status: "SUCCESS!!!!!!"}); }); var sub2 = express(); sub2.get("/", function(req, res){ res.json({ foo: "bar", baz: "quux" }); }); // main app var app = express(); app.use("/foo", sub2); app.use("/", sub1);

Submitted November 13, 2017 at 04:28PM by srdjus

No comments:

Post a Comment