Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!