Skip to content

Commit

Permalink
chore(gatsby): Convert develop-static to TypeScript (#22106)
Browse files Browse the repository at this point in the history
  • Loading branch information
blainekasten committed Mar 9, 2020
1 parent 8a141a5 commit 2e48f07
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
33 changes: 0 additions & 33 deletions packages/gatsby/src/commands/develop-static.js

This file was deleted.

27 changes: 27 additions & 0 deletions packages/gatsby/src/commands/develop-static.ts
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)
}
}
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import https from "https"

import bootstrapSchemaHotReloader from "../bootstrap/schema-hot-reloader"
import bootstrapPageHotReloader from "../bootstrap/page-hot-reloader"
import developStatic from "./develop-static"
import { developStatic } from "./develop-static"
import withResolverContext from "../schema/context"
import sourceNodes from "../utils/source-nodes"
import createSchemaCustomization from "../utils/create-schema-customization"
Expand Down

0 comments on commit 2e48f07

Please sign in to comment.