-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby): Convert develop-static to TypeScript (#22106)
- Loading branch information
1 parent
8a141a5
commit 2e48f07
Showing
3 changed files
with
28 additions
and
34 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
import sysPath from "path" | ||
import express from "express" | ||
import { ServeStaticOptions } from "serve-static" | ||
import parseUrl from "parseurl" | ||
|
||
export function developStatic( | ||
root: string, | ||
options: ServeStaticOptions | ||
): express.Handler { | ||
const expressStatic = express.static(root, options) | ||
|
||
return function( | ||
req: express.Request, | ||
res: express.Response, | ||
next: express.NextFunction | ||
): typeof expressStatic | void { | ||
if ([`GET`, `HEAD`].includes(req.method)) { | ||
const path = parseUrl(req).pathname | ||
const parsedPath = sysPath.parse(path) | ||
if ([`.htm`, `.html`].includes(parsedPath.ext)) { | ||
return next() | ||
} | ||
} | ||
|
||
return expressStatic(req, res, 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