Tag: redirect

如何redirect页面的标题?

我想redirect页面来修改标题的职位。 但是我发现在头部redirect在技术上是不可能的。 如果我发送请求到带有头部的节点服务器,将页面redirect到发布修改页面,那么没有办法使用头部redirect到不使用多个路由器的页面(因为路由器function只是用于渲染帕格文件,它们不能同时完成)

Nodejs res.redirect不工作?

我有我的Angularjs网站,我试图将所有的Httpstream量路由到Https ,为此,我已经写了下面的代码,但它不工作,每次我打开我的网站上Httpredirect没有发生。 var express = require('express'); var app = express(); app.use(express.static(__dirname + '/public')); // Website part added var bodyParser = require('body-parser') app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })) app.use(function(req,res,next) { if(req.headers["x-forwarded-proto"] == "http") { res.redirect("https://" + req.headers.host + req.url); return next(); } else { console.log('Request was not HTTP'); return next(); } }); app.set('views', path.join(__dirname, 'views')); app.set('view engine', […]

Express Node.js框架:如何通过replace一个命名的参数段来重新编写一个URL?

在我的Express应用程序中,当路线中的某些参数符合某些条件时,我想使用路线参数前提条件执行一些redirect。 作为一个例子,假设我希望将参数word转换为全部大写,如果还没有的话。 参数word可能出现在几个不同的路由中,例如/:word , /foo/:word , /foo/:word/bar等等。幸运的是,在路由参数前提下,例如(CoffeeScript中的代码): app.param 'word', (req, res, next, word) -> if word isnt word.toUpperCase() new_URL = // current URL, but replace word with word.toUpperCase() // res.redirect new_URL, 301 我的问题是关于如何构造new_URL ,用它的大写等价物replace:word 。 我希望能够使用相同的函数构造new_URL ,而不pipe当前正在使用哪条path。 我看到有req.route ,但没有定义。 我想我可以通过req.app.routes.routes.get[req._route_index]访问当前匹配的路由,然后拆分path ,并重新构build它,但似乎过于复杂。 有没有办法简单地迭代当前路线的path段? 谢谢!

域名有或没有“www”

我有一个域,例如名为www.example.com,当人们inputexample.com时,它仍然可以被访问,但不会自动将该“www”添加到URL中。 但是对于像Facebook这样的网站,如果你inputfacebook.com,它会自动添加“www”,在为你加载页面之前。 大概我没有解释得很清楚,但是猜猜你看到了不同之处,无论如何也得到了我的观点。 那么,如何让我的域名像脸书一样,当人们inputexample.com时,它会自动为他们添加www? 编辑:好的,所以我需要redirect到“www”子域。 实际上,我使用Amazon EC2上托pipe的nodejs来为网页提供服务,而不是Apache HTTP。 那么nodejs区域中的任何等价的.htaccess? 我想现在问题转移到更多的nodejs导向,结果它成为这个线程的冗余: 使用Express 3redirect所有请求? 感谢你的帮助。

ExpressJS / NodeJSredirect图像

img可以将src值redirect到另一个页面? 鉴于,我有img : <img src='/images/fileName'/> 在app.js中 app.get('/images/:fileName', subject.image); 这是我的路线: exports.image = function(req, res){ var fileName = req.fileName; fs.exists(fileName, function(exists){ if (exists) { res.sendfile(imagePath); }else{ res.redirect('http://gravatar.com/avatar/_some_hash'); } }); } 我的代码工作,但如果图像不存在,使用res.redirect可以吗? 谢谢

快递 – 如何修改请求,然后redirect到另一个路线?

我正在寻找一种方法来修改我的请求之前redirect到我的express.js应用程序中的另一个路线。 我尝试了两种方法来做到这一点: 1) #users.coffee router.use '/:id', (req, res, next) -> req.currentUser = req.params.id req.url = '/' next() #app.coffee app.use '/users', require('./routes/users') app.get '/', (req, res) -> locals = {} if req.currentUser locals.currentUser = req.currentUser res.render 'index', locals 2) #users.coffee router.use '/:id', (req, res, next) -> req.currentUser = req.params.id res.redirect '/' #app.coffee app.use '/users', require('./routes/users') app.get […]

请求nodejs模块不支持一些url的redirect

我正在使用请求nodejs模块来获取一个网站的HTML,但不是一些redirect网站的工作如下: var request = require('request'); var options = { url: "http://www.amwasia.com", headers: {'user-agent': 'node.js'}, rejectUnauthorized: false, followAllRedirects: true }; request(options, function (error, response, body) { if (!error && response.statusCode == 200) { console.log("body>>>>>>"+body) } else { console.log("error>>>>>>>>>" + error); console.log("response statusCode>>>>>>>>>" + response.statusCode); console.log("response body>>>>>>>>>" + response.body); } }); 这给了我这个输出 身体>>>>>> <!DOCTYPE html PUBLIC "-//W3C//DTD […]

用koa-routerredirectkoa中的嵌套路由

我如何使用koa-router做嵌套路由redirect? app.js: var router = require('koa-router')(); var route1 = require('./routes/route1'); var route2 = require('./routes/route2'); router.use('/route1', route1); router.use('/route2', route2); app.use(router.routes()); route1.js: var router = require('koa-router')(); router.all('/', function *() { router.redirect('/route2'); }); module.exports = router.routes(); route2.js: var router = require('koa-router')(); router.all('/', function *() { this.body = "route2"; }); 上面的代码在导航到/route1时导致以下错误: TypeError: Cannot read property '0' of undefined at […]

Nodejs + express + OpenId连接redirect到根

我已经在我的应用程序中集成了Passport OpenId Connect( https://github.com/jaredhanson/passport-openidconnect )成功 passport.use('provider', new OICStrategy({ issuer: "https://fssfed.stage.ge.com/fss", authorizationURL : "https://MYFEDERATIONURL/authorization.oauth2", tokenURL : "https://MYFEDERATIONURL/token.oauth2", userInfoURL : "https://MYFEDERATIONURL/userinfo.openid", callbackURL : "http://MYRETURNURL:5000", clientID: "MYSECRET", clientSecret: "MYPASSWORD" }, function(accessToken, refreshToken, profile, done) { console.log(accessToken); console.log(refreshToken); console.log("profile:") console.log(profile); console.log(done); return done(null, profile); } )); 和 app.use('/', function(req, res, next) { console.log(req.url + " " + req.isAuthenticated()); if […]

使用NodeJS收集所有redirect的URL的URL

我想检索从源URL Xredirect的URL列表,它可能有许多redirect的URL,但我想要它的所有列表。 例如: http://www.example.com/origin-url 它将redirect到 http://www.example.com/first-redirect 再次将redirect到 http://www.example.com/second-redicect 最后是这个 http://www.example.com/final-url 所以我想要的是使用NodeJs或Express的所有这些URL的列表 http://www.example.com/origin-url –>> http://www.example.com/first-redirect –>> http://www.example.com/second-redicect –>> http://www.example.com/final-url 给我这个build议,我应该使用哪个节点模块来实现这一点。 提前致谢。