where i can set the default path for a Mean Stack Application? Local path is
http://localhost:3000
but i'd like the application starts at
http://localhost:3000/myapp/
In my mind i would expect my routing won't change:
const appRoutes: Routes = [
{ path: '', component: HomeComponent, pathMatch: 'full', canActivate: [AuthGuard] },
{ path: 'login', component: AuthComponent },
{ path: 'register', component: RegisterComponent },
// otherwise redirect to home
{ path: '**', redirectTo: '' }
];
When i deploy on my server i want to have my application running on port 80 and in its separated context, like this:
http://www.myserver.com/myapp/
the routing sounds like this:
http://www.myserver.com/myapp/home
http://www.myserver.com/myapp/login
and if i point on a not set route:
http://www.myserver.com/myapp/notexists
it redirects on its base:
http://www.myserver.com/myapp/
thanks in advance.
I found a solution.
client side: In the main view (is it's a single page application) in the head section we should set the base href path.
<!DOCTYPE html>
<html>
<head>
<base href="/my-base-path">
<title>My-pplication</title>
<link rel="stylesheet"
</head>
All my request will start with
http://mysite/my-base-path/...
Server side:
I'm using Express so, when starts the app.js (or whatever it is the name):
var express = require('express');
...
var app = express();
...
// Define where are located the external apis
var appRoutes = require('./routes/app');
var authRoutes = require('./routes/auth');
var registerRoutes = require('./routes/register');
var userr = require('./routes/userProfile');
...
...
app.use('/my-base-path/', appRoutes);
app.use('/my-base-path/user',userRoutes)
app.use('/my-base-path/login', authRoutes);
app.use('/my-base-path/register', registerRoutes);
Hope this it can be useful.