简体   繁体   中英

TypeError: response.redirect is not a function

I need help...

So, I have this code

var express = require('express');
var app = express();
//Sites
// Landingpage CourseWorkers ----------------------------------------
app_courseworkers = require('./sites/app')
app_https_courseworkers = (req, response) => response.redirect("https://courseworkers.com")

But when I run it on the server I get the message:

0|index  | TypeError: response.redirect is not a function
0|index  |     at Object.app_https_courseworkers [as handler] (/var/www/html/courseworkers/index.js:9:55)
0|index  |     at Server.overallHandler (/var/www/html/courseworkers/node_modules/vhttps/lib/init.js:103:25)
0|index  |     at emitTwo (events.js:126:13)
0|index  |     at Server.emit (events.js:214:7)
0|index  |     at parserOnIncoming (_http_server.js:619:12)
0|index  |     at HTTPParser.parserOnHeadersComplete (_http_common.js:115:23)

Can anyone point out what I'm doing wrong?

Note: Running in localhost it goes normally

If you are trying to redirect to an external URL when someone goes to a specific URL on your site, try this:

app.get("/course", (req, res) => {
  res.redirect("https://courseworkers.com");
});

My guess is, you are trying to call app_https_courseworkers(req, response) , but you aren't actually passing in a valid response object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM