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

189
Views
Conditionally serve ejs and react.js builds in smae url

I want to serve ejs and react.js conditionally to the user. When the user visits the page he would be landed to a login page which would be served from ejs. Once he logins in successfully which would be through an OAUTH, I want to serve the react.js build of the app.

const path = require("path");
const express = require("express");
const app = express(); // create express app
let ejs = require('ejs');

// app.get('/login', (req, res) =\> {
//   app.set("view engine", "ejs");
//   res.render('index');
// });

app.use('/', express.static(path.join(\__dirname, "..", "build"))); //React.js prod build path
app.use('/', express.static("public"));

app.get('\*', (req, res) =\> {
  if(true) {
    app.set("view engine", "ejs");
    res.render('index');
  } else {
    res.sendFile("index.html", { root: path.join(\__dirname, "..", "build") });
  }  
});

// start express server on port 3000
app.listen(3000, () =\> {
  console.log("server started on port 3000");
});

Any help regarding the serving of both apps would be highly appreciated.

about 4 years ago · Juan Pablo Isaza
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!