I have 2 angular apps one is web
and other one is admin
. I used NodeJS
and Express
server to serve this app. For the web url is staring with the / (ex: mydomain.com/) and its work fine. Now i want to access admin panel via mydomain.com/admin
but its show me error in console.
Error: Cannot match any routes. URL Segment: 'admin'
Note : Both apps ( web and admin ) are separate angular app.
I tried to serve admin interface using proxy_pass in nginx configratio, But it not worked
Here is my routing congigation in NodeJs Server
app.js
//Routing
const WEB = require('./routes/web')
const ADMIN = require('./routes/admin')
//app.use('/',WEB);
app.use('/admin/',ADMIN);
app.use('/',WEB);
/routes/web.js
Router.get('*',(req,res) =>{
// server from angular build using comand ng build
res.sendFile(path.join(APP_PATH,'build/index.html'));
})
/routes/admin.js
Router.get('*',(req,res) =>{
// server from angular build using command ng build
res.sendFile(path.join(APP_PATH,'admin/index.html'));
})
How can I serve two different apps using the same nodeJS server?
This should work
app.use('/',express.static('build'));
app.use('/admin',express.static('admin'));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.