Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
Mean Stack: set default path

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.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda