How to use the http-status-codes.MOVED_PERMANENTLY function in http-status-codes

To help you get started, we’ve selected a few http-status-codes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pencilblue / pencilblue / include / http / request_handler2.js View on Github external
action: function(req, res, next) {
                        var hostname = req.handler.hostname;
                        var siteObj = RequestHandler2.sites[hostname];
                        var redirectHost = RequestHandler2.redirectHosts[hostname];

                        // If we need to redirect to a different host
                        if (!siteObj && redirectHost && RequestHandler2.sites[redirectHost]) {
                            return req.handler.doRedirect(pb.SiteService.getHostWithProtocol(redirectHost), HttpStatus.MOVED_PERMANENTLY);
                        }
                        req.handler.siteObj = req.siteObj = siteObj;

                        //derive the localization. We do it here so that if the site isn't
                        //available we can still have one available when we error out
                        req.handler.localizationService = req.localizationService = req.handler.deriveLocalization({ session: req.session });

                        //make sure we have a site
                        if (!siteObj) {
                            return next(new Error("The host (" + hostname + ") has not been registered with a site. In single site mode, you must use your site root (" + pb.config.siteRoot + ")."));
                        }

                        req.handler.site = req.site = req.handler.siteObj.uid;
                        req.handler.siteName = req.siteName = req.handler.siteObj.displayName;

                        next();
github pencilblue / pencilblue / include / http / middleware / index.js View on Github external
static deriveSite (req, res, next) {
            var hostname = req.handler.hostname;
            var siteObj = RequestHandler.sites[hostname];
            var redirectHost = RequestHandler.redirectHosts[hostname];

            // If we need to redirect to a different host
            if (!siteObj && redirectHost && RequestHandler.sites[redirectHost]) {
                return req.router.redirect(pb.SiteService.getHostWithProtocol(redirectHost), HttpStatus.MOVED_PERMANENTLY);
            }
            req.handler.siteObj = req.siteObj = siteObj;

            //derive the localization. We do it here so that if the site isn't
            //available we can still have one available when we error out
            req.handler.localizationService = req.localizationService = req.handler.deriveLocalization({session: req.session});

            //make sure we have a site
            if (!siteObj) {
                return next(new Error("The host (" + hostname + ") has not been registered with a site. In single site mode, you must use your site root (" + pb.config.siteRoot + ")."));
            }

            req.handler.site = req.site = req.handler.siteObj.uid;
            req.handler.siteName = req.siteName = req.handler.siteObj.displayName;

            next();
github electrode-io / electrode / packages / electrode-react-webapp / lib / http-status.js View on Github external
"use strict";

const HttpStatusCodes = require("http-status-codes");

module.exports = {
  // Status codes where we want to redirect the user
  redirect: {
    [HttpStatusCodes.MOVED_PERMANENTLY]: true,
    [HttpStatusCodes.MOVED_TEMPORARILY]: true,
    [HttpStatusCodes.PERMANENT_REDIRECT]: true,
    [HttpStatusCodes.TEMPORARY_REDIRECT]: true
  }
};
github mozilla / voice-web / server / src / server.ts View on Github external
app.use((request, response, next) => {
      // redirect to omit trailing slashes
      if (request.path.substr(-1) == '/' && request.path.length > 1) {
        const query = request.url.slice(request.path.length);
        response.redirect(
          HttpStatus.MOVED_PERMANENTLY,
          request.path.slice(0, -1) + query
        );
      } else {
        next();
      }
    });
github pencilblue / pencilblue / test / include / http / middleware / index.spec.js View on Github external
it('should do a redirect when the controller result contains a string typed redirect property', function(done) {
            req.controllerResult = { redirect: '/', code: HttpStatusCodes.MOVED_PERMANENTLY };
            sandbox.stub(req.handler, 'doRedirect').withArgs(req.controllerResult.redirect, req.controllerResult.code);

            this.pb.Middleware.writeResponse(req, res, function(err) {
                should(err).eql(undefined);
                req.didRedirect.should.eql(true);
                req.handler.doRedirect.calledOnce.should.eql(true);
                done();
            });
        });
github pencilblue / pencilblue / test / include / http / middleware / index.spec.js View on Github external
it('should redirect when an outdated hostname is used for a site', function() {
            this.pb.RequestHandler.sites = {
                'test2.localhost:8080': {}
            };
            this.pb.RequestHandler.redirectHosts = {
                'test1.localhost:8080': 'test2.localhost:8080'
            };
            req.router = {
                redirect: function(){}
            };
            sandbox.stub(req.router, 'redirect').withArgs(sinon.match.string, HttpStatusCodes.MOVED_PERMANENTLY);
            this.pb.Middleware.deriveSite(req, res, function() {});
            req.router.redirect.calledOnce.should.eql(true);
        });
github springernature / thundermole / lib / thundermole.js View on Github external
mole.statsd.increment('api_response');
		mole.statsd.timing('api_response_time', response.timer.end());
		if (error) {
			mole.logger.error('Error in API request: %s', error.stack);
			mole.statsd.increment('api_error');
			return handleError(error, request, response);
		}
		if (apiResponse.redirect && !apiResponse.target) {
			mole.logger.info(
				'Redirecting request %s to %s (%d)',
				request.url,
				apiResponse.redirect,
				(apiResponse.redirect_type || httpStatus.MOVED_PERMANENTLY)
			);
			response.writeHead(
				(apiResponse.redirect_type || httpStatus.MOVED_PERMANENTLY),
				apiRedirectHeaders(apiResponse)
			);
			return response.end();
		}
		proxyUserRequest(mole, request, response, apiResponse);
	});
}
github springernature / thundermole / lib / thundermole.js View on Github external
api.get(request, options.routes, function (error, apiResponse) {
		mole.statsd.increment('api_response');
		mole.statsd.timing('api_response_time', response.timer.end());
		if (error) {
			mole.logger.error('Error in API request: %s', error.stack);
			mole.statsd.increment('api_error');
			return handleError(error, request, response);
		}
		if (apiResponse.redirect && !apiResponse.target) {
			mole.logger.info(
				'Redirecting request %s to %s (%d)',
				request.url,
				apiResponse.redirect,
				(apiResponse.redirect_type || httpStatus.MOVED_PERMANENTLY)
			);
			response.writeHead(
				(apiResponse.redirect_type || httpStatus.MOVED_PERMANENTLY),
				apiRedirectHeaders(apiResponse)
			);
			return response.end();
		}
		proxyUserRequest(mole, request, response, apiResponse);
	});
}
github Prior99 / hyrest / packages / hyrest / src / answers.ts View on Github external
export function movedPermanently(arg1: T | string | Wrapper, arg2?: string): T {
    return answer(HTTP.MOVED_PERMANENTLY, arg1, arg2);
}