PerfectWebRedirects

master

Filter for specified routes (including trailing wildcard routes) and perform redirects as instructed if a match is found.
PerfectlySoft/Perfect-WebRedirects

Perfect Web Redirects

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 4.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

Perfect Web Redirects Demo

The Perfect WebRedirects module will filter for specified routes (including trailing wildcard routes) and perform redirects as instructed if a match is found.

A demo showing the usage, and working of the Perfect WebRedirects module can be found at https://github.com/PerfectExamples/Perfect-WebRedirects-Demo.

Including in your project

Import the dependency into your project by specifying it in your project's Package.swift file, or adding it via Perfect Assistant.

.Package(url: "https://github.com/PerfectlySoft/Perfect-WebRedirects", majorVersion: 3),

Then in your main.swift file where you configure your web server, add it as an import, and add the filter:

import PerfectWebRedirects

Adding the filter:

// Add to the "filters" section of the config:
[
	"type":"request",
	"priority":"high",
	"name":WebRedirectsFilter.filterAPIRequest,
]

If you are also adding Request Logger filters, if the Web Redirects object is added second, directly after the RequestLogger filter, then both the original request (and it's associated redirect code) and the new request, will be logged correctly.

Configuration file

The configuration for the routes is included in JSON files at /config/redirect-rules/*.json in the form:

{

  "/test/no": {
	"code": 302,
	"destination": "/test/yes"
  },

	"/test/no301": {
		"code": 301,
		"destination": "/test/yes"
  },
  
	"/test/wild/*": {
		"code": 302,
		"destination": "/test/wildyes"
  },

	"/test/wilder/*": {
		"code": 302,
		"destination": "/test/wilding/*"
  }

}

Note that multiple JSON files can exist in this directory - all will be loaded the first time the filter is invoked.

Compatibility with Swift

The master branch of this project currently compiles with Xcode 9 or the Swift 4 toolchain on Ubuntu.

Further Information

For more information on the Perfect project, please visit perfect.org.

Description

  • Swift Tools 4.0.0
View More Packages from this Author

Dependencies

Last updated: Fri Oct 18 2024 14:55:54 GMT-0900 (Hawaii-Aleutian Daylight Time)