Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next #4

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"presets": ["@babel/preset-env"]
"presets": [
"@babel/preset-env"
],
"plugins": [
["@babel/plugin-transform-runtime", {
"regenerator": true
}]
]
}
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# nextjs-middleware-chain

## v0.0.8

_2021-02-14_

### Features

### Updates

- fix: swap @babel/polyfill for @babel/plugin-transform-runtime to prevent undefined regeneratorRuntime
- fix: set client project to install from parent directory rather than registry
9 changes: 9 additions & 0 deletions client/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
"next/babel",
// Add your babel presets here
],
"plugins": [
// Add your babel plugins here
]
}
15,081 changes: 9,310 additions & 5,771 deletions client/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"next": "^11.0.0",
"nextjs-middleware-chain": "^0.0.3",
"next": "^11.1.2",
"nextjs-middleware-chain": "file:..",
"react": "17.0.2",
"react-dom": "17.0.2"
},
Expand Down
16 changes: 10 additions & 6 deletions client/src/middleware/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createMiddleware } from '../../../src/index'
// import { createMiddleware } from '../../../src/index'
import { createMiddleware } from 'nextjs-middleware-chain'

const fnA = (req, res, next) => {
console.log('Running A', next)
Expand All @@ -9,8 +10,8 @@ const fnA = (req, res, next) => {
const fnB = async (req, res, next) => {
console.log('Running B', next)

const result = await new Promise(resolve => setTimeout(resolve, 2000));
const result = await new Promise((resolve) => setTimeout(resolve, 2000))

return next('B')
}

Expand Down Expand Up @@ -43,8 +44,9 @@ const decorate = (req, res, next) => {

const unauthorized = (req, res, next) => {
if (req.nmc.type === 'api') {
res.status(401).json({error: 'unauthorize', message: 'access denied'})
} else if (req.nmc.type === 'ssr') {
res.status(401).json({ error: 'unauthorize', message: 'access denied' })
}
else if (req.nmc.type === 'ssr') {
return next('end', {
redirect: {
destination: '/',
Expand All @@ -62,9 +64,11 @@ const unauthorized = (req, res, next) => {

const common = async (req, res, next) => {
const aReturn = fnA(req, res, next)

console.log('aRes', aReturn)

const bReturn = await fnB(req, res, next)

console.log('bRes', aReturn)

const authReturn = unauthorized(req, res, next)
Expand Down Expand Up @@ -114,4 +118,4 @@ const mwFactory = createMiddleware(middlewareFunctionsArray, optionsObject)
const preBuiltChain = mwFactory().fnA().fnB().fnC()

export { preBuiltChain }
export default mwFactory
export default mwFactory
4 changes: 2 additions & 2 deletions client/src/pages/ssr-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ export const getServerSideProps = middleware()
.finish(getProps, 'SSR Import')

// export const getServerSideProps = preBuiltChain
// .fnD()
// .finish(getProps, 'SSR Import PreBuilt')
// .fnD()
// .finish(getProps, 'SSR Import PreBuilt')
Loading