Install this code in server.js on the node side, manage routes from angular, the side routing file means determining the path, for example, “admin / userdetails” , here is my server.js .
var express = require('express');
var app = express();
var path = require('path');
var config = require('./server/config/db');
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({limit: '16mb'}));
app.use(function(req, res, next) {
res.setHeader("Access-Control-Allow-Methods", "POST, PUT, OPTIONS,
DELETE, GET");
res.header("Access-Control-Allow-Origin",
"http://localhost:3000");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-
With, Content-Type, Accept");
res.header("Access-Control-Allow-Credentials", true);
next();
});
app.use('/', require('./server/routes/api'));
app.use('/root', express.static(path.join(__dirname, '/')));
app.use('/backDist',express.static(path.join(__dirname,
'/admin/dist/')));
app.use('/dist',express.static(path.join(__dirname,'/client/dist/')));
app.use('/image',express.static(__dirname+'/admin/src/uploads'));
app.get('/', function (req, res, err) {
res.sendFile(path.join(__dirname+'/client/dist','index.html'))
});
app.get('/admin/*', function (req, res) {
res.sendFile(path.join(__dirname+'/admin/dist','index.html'))
});
app.get('/admin', function (req, res) {
res.sendFile(path.join(__dirname+'/admin/dist','index.html'))
});
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
app.listen(3000, function () {
console.log('Example listening on port 3000!');
});
module.exports = app;
source
share