-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(middleware): oops page for php bots (#218)
* refactor(middleware): oops page for php bots * refactor(middleware): wip * refactor(middleware): simple ops page * chore: fix skip logic * chore: rename * chore: rename
- Loading branch information
Showing
17 changed files
with
182 additions
and
43 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,7 @@ | ||
import ErrorPage from 'next/error' | ||
|
||
const NotFound = () => { | ||
return <ErrorPage statusCode={404} title="Page Not Found" /> | ||
} | ||
|
||
export default NotFound |
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,35 @@ | ||
'use client' | ||
|
||
import { useRouter } from 'next/navigation' | ||
|
||
import { ROUTE } from '@/constant/route' | ||
|
||
import Button from '@/widgets/Buttons/Button' | ||
import { LinkAble } from '@/widgets/Common' | ||
|
||
import { Wrapper, InnerWrapper, Footer } from './styles' | ||
// import ErrorPage from 'next/error' | ||
|
||
const OopsPage = () => { | ||
const router = useRouter() | ||
|
||
return ( | ||
<Wrapper> | ||
<InnerWrapper> | ||
<h1>Oops</h1> | ||
<p>the content you looking for is not exist</p> | ||
<Footer> | ||
<Button type="primary" right={20} onClick={() => router.back()}> | ||
返回 | ||
</Button> | ||
|
||
<LinkAble href={`/${ROUTE.HOME}`}> | ||
<Button ghost>Groupher 社区</Button> | ||
</LinkAble> | ||
</Footer> | ||
</InnerWrapper> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
export default OopsPage |
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,18 @@ | ||
import Link from 'next/link' | ||
|
||
import styled, { css, theme } from '@/css' | ||
|
||
export const Wrapper = styled.div` | ||
${css.column('align-both')}; | ||
width: 100%; | ||
height: 68vh; | ||
position: relative; | ||
` | ||
export const InnerWrapper = styled.div` | ||
${css.column('align-start')}; | ||
position: relative; | ||
` | ||
export const Footer = styled.div` | ||
${css.row()}; | ||
margin-top: 20px; | ||
` |
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
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,18 +1,19 @@ | ||
import { NextResponse } from 'next/server' | ||
import type { NextRequest } from 'next/server' | ||
|
||
import { applyMiddleware } from './middlewares/helper' | ||
// import { themeMiddleware } from './middlewares/theme' | ||
import { queryWhitelistMiddleware } from './middlewares/query-whitelist' | ||
import { oopsMiddleware } from './middlewares/oops' | ||
import { avoidScanMiddleware } from './middlewares/avoid-scan' | ||
|
||
export function middleware(request: NextRequest) { | ||
// const response = themeMiddleware(request) | ||
// if (response instanceof NextResponse) return response | ||
// middleware in this array will be applied in order | ||
const middlewareFunctions = [ | ||
avoidScanMiddleware, | ||
oopsMiddleware, | ||
queryWhitelistMiddleware, | ||
// ... more middlewares | ||
] | ||
|
||
// whitelist the query parameters to improve CDN caching | ||
const response = queryWhitelistMiddleware(request) | ||
if (response instanceof NextResponse) return response | ||
|
||
// return response instanceof NextResponse ? response : NextResponse.next() | ||
|
||
return NextResponse.next() | ||
return applyMiddleware(middlewareFunctions, request) | ||
} |
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 @@ | ||
import { NextResponse } from 'next/server' | ||
import type { NextRequest } from 'next/server' | ||
|
||
import { ROUTE } from '@/constant/route' | ||
|
||
export function avoidScanMiddleware(req: NextRequest) { | ||
const { pathname } = req.nextUrl | ||
|
||
// 检查pathname是否以.php或.php7结束 | ||
if (pathname.endsWith('.php') || pathname.endsWith('.php7')) { | ||
// 重定向到/oops页面 | ||
return NextResponse.redirect(new URL(ROUTE.OOPS, req.url)) | ||
} | ||
|
||
// 如果路径不以.php或.php7结束,则继续处理后续中间件 | ||
return NextResponse.next() | ||
} |
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,20 @@ | ||
import { NextResponse } from 'next/server' | ||
|
||
/** | ||
* chain the middlewares and apply them to the request | ||
*/ | ||
export function applyMiddleware(middlewareFns, req) { | ||
for (const middlewareFn of middlewareFns) { | ||
const response = middlewareFn(req) | ||
// 如果中间件执行结果是重定向或重写,那么就返回该响应并且不再执行后续中间件 | ||
|
||
if (response instanceof NextResponse) { | ||
// 检查状态码是否代表重定向 | ||
if (response.status >= 300 && response.status < 400) { | ||
return response | ||
} | ||
} | ||
} | ||
|
||
return NextResponse.next() | ||
} |
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 @@ | ||
import { NextResponse } from 'next/server' | ||
import type { NextRequest } from 'next/server' | ||
|
||
import { ROUTE } from '@/constant/route' | ||
|
||
export function oopsMiddleware(req: NextRequest) { | ||
const { pathname } = req.nextUrl | ||
|
||
// 若路径为 /404,则重定向到自定义404页面 | ||
// just demo | ||
if (pathname === '/404') { | ||
// return NextResponse.rewrite(new URL(ROUTE.OOPS, req.url)) | ||
return NextResponse.redirect(new URL(ROUTE.OOPS, req.url)) | ||
} | ||
|
||
return NextResponse.next() | ||
} |
Oops, something went wrong.