Giter VIP home page Giter VIP logo

Comments (3)

a-roussos avatar a-roussos commented on July 30, 2024

The following code segments might be of interest:

urungi/server/app.js

Lines 69 to 71 in 567a6d5

staticRouter.all('*', function (req, res) {
res.sendStatus(404);
});

urungi/server/app.js

Lines 136 to 140 in 567a6d5

// Catch-all route, it should always be defined last
app.get('*', function (req, res) {
res.cookie('XSRF-TOKEN', req.csrfToken(), { sameSite: true });
res.render('index', { base: config.get('base') });
});

And here's how I have attempted to fix this (I'm not an Express / Node.js expert by any means!):

diff --git a/server/app.js b/server/app.js
index 103fef95..2cc94bc0 100644
--- a/server/app.js
+++ b/server/app.js
@@ -136,7 +136,13 @@ for (const routesModule of routesModules) {
 // Catch-all route, it should always be defined last
 app.get('*', function (req, res) {
     res.cookie('XSRF-TOKEN', req.csrfToken(), { sameSite: true });
-    res.render('index', { base: config.get('base') });
+    if ( req.originalUrl === '/' ||
+         req.originalUrl === '/login' ||
+         req.originalUrl === '/home' ) {
+        res.render('index', { base: config.get('base') });
+    } else {
+        res.sendStatus(404);
+    }
 });

 module.exports = app;

from urungi.

jajm avatar jajm commented on July 30, 2024

The problem here is that the backend does not know about the frontend URLs. So it renders the index page which contains the Angular.js app and let the client's browser do the rest.
Doing what you suggest would prevent linking to (or reloading) pages other than the home page, ie. it will return a 404 for URLs like /dashboards/list whereas it is a valid URL

from urungi.

jajm avatar jajm commented on July 30, 2024

You might want to try the stop-angularjs branch which is in a work-in-progress state but is usable. It is an ongoing (though in pause at the moment) work to remove angular.js and it uses a more "traditional" way of handling URLs (no client-side routing).
Unknown URLs will return a 404.

from urungi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.