Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda