-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9650ae9
commit 7212fa8
Showing
20 changed files
with
2,196 additions
and
2,518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Common | ||
node_modules | ||
dist | ||
.nuxt | ||
coverage | ||
|
||
# Plugin | ||
lib/plugin.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,7 @@ module.exports = { | |
parser: 'babel-eslint', | ||
sourceType: 'module' | ||
}, | ||
extends: '@nuxtjs' | ||
extends: [ | ||
'@nuxtjs' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ node_modules | |
*.log* | ||
.nuxt | ||
.vscode | ||
.DS_STORE | ||
.DS_Store | ||
coverage | ||
dist | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', { | ||
targets: { | ||
esmodules: true | ||
} | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
extends: [ | ||
'@commitlint/config-conventional' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
hooks: { | ||
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', | ||
'pre-commit': 'yarn lint', | ||
'pre-push': 'yarn lint' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'lib/**/*.js', | ||
'!lib/plugin.js' | ||
], | ||
moduleNameMapper: { | ||
'^~/(.*)$': '<rootDir>/lib/$1', | ||
'^~~$': '<rootDir>', | ||
'^@@$': '<rootDir>', | ||
'^@/(.*)$': '<rootDir>/lib/$1' | ||
}, | ||
transform: { | ||
'^.+\\.js$': 'babel-jest' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
/* eslint-disable no-console */ | ||
|
||
// Creates new middleware using provided options | ||
function create(rules) { | ||
module.exports = function (rules) { | ||
return async function redirectRoute(req, res, next) { | ||
const decodedBaseUrl = decodeURI(req.url) | ||
const foundRule = rules.find(o => o.from.test(decodedBaseUrl)) | ||
|
||
if (!foundRule) { | ||
return next() | ||
} | ||
|
||
// Expect rule 'to' to either a | ||
// 1) regex | ||
// 2) string | ||
// 3) function taking from & req (when from is regex, req might be more interesting) | ||
|
||
const toTarget = typeof foundRule.to === 'function' ? await foundRule.to(foundRule.from, req) : foundRule.to | ||
|
||
const toUrl = decodedBaseUrl.replace(foundRule.from, toTarget) | ||
|
||
res.statusCode = foundRule.statusCode || 302 | ||
res.setHeader('Location', toUrl) | ||
res.end() | ||
} | ||
} | ||
|
||
module.exports = create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,54 @@ | ||
{ | ||
"name": "@nuxtjs/redirect-module", | ||
"version": "0.2.0", | ||
"description": "", | ||
"description": "Nuxt module to dynamically redirect initial requests", | ||
"keywords": [ | ||
"nuxtjs", | ||
"nuxt", | ||
"redirect", | ||
"seo" | ||
], | ||
"license": "MIT", | ||
"contributors": [ | ||
{ | ||
"name": "Alexander Lichter <npm@lichter.io>" | ||
} | ||
"Alexander Lichter <npm@lichter.io>" | ||
], | ||
"main": "lib/module.js", | ||
"repository": "https://github.com/nuxt-community/redirect-module", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"dev": "nuxt test/fixture", | ||
"lint": "eslint lib test", | ||
"commitlint": "commitlint -e $GIT_PARAMS", | ||
"test": "yarn lint && jest", | ||
"release": "standard-version && git push --follow-tags && npm publish" | ||
"release": "yarn test && standard-version && git push --follow-tags && npm publish" | ||
}, | ||
"eslintIgnore": [ | ||
"lib/templates/*.*" | ||
], | ||
"files": [ | ||
"lib" | ||
], | ||
"keywords": [ | ||
"nuxtjs", | ||
"nuxt", | ||
"redirect", | ||
"seo" | ||
], | ||
"engines": { | ||
"node": ">=8.0.0", | ||
"npm": ">=5.0.0" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"collectCoverage": true, | ||
"coveragePathIgnorePatterns": [ | ||
"/node_modules/", | ||
"/test/fixture" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^7.2.1", | ||
"@commitlint/config-conventional": "^7.1.2", | ||
"@nuxtjs/eslint-config": "^0.0.1", | ||
"babel-eslint": "^10.0.1", | ||
"codecov": "^3.1.0", | ||
"eslint": "^5.9.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-jest": "^22.0.0", | ||
"eslint-plugin-node": "^8.0.0", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"eslint-plugin-vue": "^4.7.1", | ||
"husky": "^1.2.0", | ||
"jest": "^24.0.0", | ||
"jsdom": "^13.0.0", | ||
"nuxt": "^2.3.2", | ||
"standard-version": "^4.4.0" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm run lint", | ||
"commit-msg": "npm run commitlint" | ||
} | ||
"@babel/core": "latest", | ||
"@babel/preset-env": "latest", | ||
"@commitlint/cli": "latest", | ||
"@commitlint/config-conventional": "latest", | ||
"@nuxtjs/eslint-config": "latest", | ||
"babel-eslint": "latest", | ||
"babel-jest": "latest", | ||
"codecov": "latest", | ||
"eslint": "latest", | ||
"eslint-config-standard": "latest", | ||
"eslint-plugin-import": "latest", | ||
"eslint-plugin-jest": "latest", | ||
"eslint-plugin-node": "latest", | ||
"eslint-plugin-promise": "latest", | ||
"eslint-plugin-standard": "latest", | ||
"eslint-plugin-vue": "latest", | ||
"get-port": "latest", | ||
"husky": "latest", | ||
"jest": "latest", | ||
"jsdom": "latest", | ||
"nuxt-edge": "latest", | ||
"request": "latest", | ||
"request-promise-native": "latest", | ||
"standard-version": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<template> | ||
<div> | ||
<div> | ||
Works! | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
} | ||
</script> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
const { redirects, baseConfig } = require('./utils') | ||
|
||
module.exports = Object.assign({}, baseConfig, { redirect: redirects }) | ||
module.exports = Object.assign({}, baseConfig, { | ||
modules: [ | ||
{ handler: require('../../') } | ||
], | ||
redirect: redirects | ||
}) |
Oops, something went wrong.