express-router

How to catch page not found in express router

若如初见. 提交于 2021-02-11 12:32:29
问题 I would like to catch 404 page not found error in express router. I use a basic example : const express = require('express'); const app = express(); const router = express.Router(); // ROUTER MID BEFORE router.use((req, res, next) => {console.log("Router Mid => Before"); next();}); // ROUTER PAGE /BAR router.get('/bar', (req, res, next) => { console.log("Router page '/bar'"); res.send('<body><h1>Hello World</h1></body>'); next(); }); // ROUTER NOT FOUND router.get('*', (req, res, next) =>

Route.get() requires a callback function but got a [object Undefined]. What did I do wrong?

点点圈 提交于 2021-02-10 07:19:07
问题 I have checked many answers in other pages and forums, but I still don't get it. What did I do wrong? Help me *edited. I have added requiring routes and app.use. It looks like function isLOggedIn is not exporting but I don't know how to do that. I did like this in another app, it worked there. auth-routes.js const express = require("express"), router = express.Router(), passport = require("passport") function isLoggedIn(req, res, next) { if (req.isAuthenticated()) { return next() } res

body parser logging empty object in express router

点点圈 提交于 2020-06-01 05:36:04
问题 for some reason I can see my req.body in my express server on my route req body is [Object: null prototype] { '{"password":"xxxxxxxx"}': '' } but when I log req.body.password (the object key) I get req body is undefined here's my index router for reference in my express app var express = require('express'); var router = express.Router(); var bodyParser = require('body-parser') const path = require('path'); /* GET adminPanel. */ router.post('/authenticate', function(req, res, next) { console

core.js:5873 ERROR TypeError: Cannot read property 'filename' of undefined

|▌冷眼眸甩不掉的悲伤 提交于 2020-04-29 03:54:22
问题 I am trying to store some images on my Node.JS server and read it from Angular client with the following codes: image.ts: export class Image { fieldname: string; originalname: string; encoding: string; mimetype: string; destination: string; filename: string; path: string; size: number; } image.service.ts: export class ImagesService { constructor(private http: HttpClient, private processHTTPMsgService: ProcessHTTPMsgService) { } getImages(): Observable<Image[]> { return this.http.get<Image[]>

core.js:5873 ERROR TypeError: Cannot read property 'filename' of undefined

Deadly 提交于 2020-04-29 03:54:11
问题 I am trying to store some images on my Node.JS server and read it from Angular client with the following codes: image.ts: export class Image { fieldname: string; originalname: string; encoding: string; mimetype: string; destination: string; filename: string; path: string; size: number; } image.service.ts: export class ImagesService { constructor(private http: HttpClient, private processHTTPMsgService: ProcessHTTPMsgService) { } getImages(): Observable<Image[]> { return this.http.get<Image[]>

core.js:5873 ERROR TypeError: Cannot read property 'filename' of undefined

心已入冬 提交于 2020-04-29 03:53:38
问题 I am trying to store some images on my Node.JS server and read it from Angular client with the following codes: image.ts: export class Image { fieldname: string; originalname: string; encoding: string; mimetype: string; destination: string; filename: string; path: string; size: number; } image.service.ts: export class ImagesService { constructor(private http: HttpClient, private processHTTPMsgService: ProcessHTTPMsgService) { } getImages(): Observable<Image[]> { return this.http.get<Image[]>

Can't render html with express router and passport: Bad Request or Not Found error

旧时模样 提交于 2020-01-06 07:23:46
问题 I have an express Router set up for the url that starts from /auth . Inside the file where the /auth routes are defined I am sending a whole html page to start my React app. In the html page I have many static resources that must reference the public folder. Unfortunately it is not happening. I think I need to additionally redirect or set static resources for the Router file itself. Here is the main app.js file relevant code: var express = require('express'); var app = express(); app.use

Why is my react router not passing my express route to server?

大憨熊 提交于 2019-12-13 05:16:20
问题 I tried to add social login to my (already working) react/express app, and I got it working in localhost. However, when I deploy it to production, the social login doesn't work. This is how it gets started <a href="/api/auth/google">Google+</a> However, in production, it stays at https://sample.com/api/auth/google in my browser. So, it appears the react router is catching it first before express. How? In localhost, it works because the proxy in package.js "proxy": { "/api": { "target": "http:

How to app use all routes from different file

自闭症网瘾萝莉.ら 提交于 2019-12-11 02:59:32
问题 I'm trying to separate my routes, previously i'm including them to my app.js /backend/app.js const express = require("express"); const router = require("./routes"); const status = require("./routes/status"); const register = require("./routes/register"); const login = require("./routes/login"); app.use('/', router); app.use('/status', status); app.use('/login', login); app.use('/register', register); I realized its not ideal since i am adding more and more routes later on and the app.js will