Skip to content

Commit c503237

Browse files
committed
Release v3, require Node 10, handle html edge case
Signed-off-by: Reece Dunham <[email protected]>
1 parent e085d80 commit c503237

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "static-server-rdil",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"description": "Static web server",
55
"homepage": "https://github.com/rdilweb/static-server",
66
"bin": {
@@ -53,5 +53,8 @@
5353
"repository": {
5454
"type": "git",
5555
"url": "https://github.com/rdilweb/static-server.git"
56+
},
57+
"engines": {
58+
"node": ">=10.13.0"
5659
}
5760
}

source/markdownRendering.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const render = (htmlBody: string): string => `\
1313
display: flex;
1414
justify-content: center;
1515
}
16-
#mn {
16+
.mn {
1717
width: 90%;
1818
margin-top: 2%;
1919
}
@@ -23,7 +23,7 @@ const render = (htmlBody: string): string => `\
2323
</style>
2424
</head>
2525
<body>
26-
<div id="mn">
26+
<div class="mn">
2727
${htmlBody}
2828
</div>
2929
</body>

source/serverHandling.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { lookup } from "mime-types"
22
import { join, extname } from "path"
3-
import { stat as _stat, createReadStream, readFile } from "fs"
3+
import { stat as _stat, createReadStream, readFile, existsSync } from "fs"
44
import chalk from "chalk"
55
import getHeaders from "./headers"
66
import markdown from "./markdownRendering"
@@ -19,6 +19,12 @@ const handle = (
1919
// try to look up file
2020
_stat(filePath, (err, stat) => {
2121
if (err) {
22+
// last ditch attempt to make sure this isn't just a case where its something like about-us.html
23+
// being used like /about-us in the browser, which is fairly common now
24+
if (existsSync(`${filePath}.html`)) {
25+
return handleRealFile(response, "html", enhancedSecurity, `${filePath}.html`)
26+
}
27+
2228
response.statusCode = err.code === "ENOENT" ? 404 : 500
2329
response.end()
2430
} else if (stat.isDirectory()) {
@@ -33,16 +39,17 @@ const handle = (
3339
} else {
3440
// actual file
3541
const fileExtension = extname(filePath)
42+
3643
if (fileExtension !== ".md" || !renderMarkdown) {
37-
handleRealFile(
44+
return handleRealFile(
3845
response,
3946
fileExtension,
4047
enhancedSecurity,
4148
filePath
4249
)
43-
} else {
44-
handleMarkdown(response, enhancedSecurity, filePath)
4550
}
51+
52+
handleMarkdown(response, enhancedSecurity, filePath)
4653
}
4754
})
4855
} catch (e) {
@@ -87,7 +94,7 @@ const handleRealFile = (
8794
) => {
8895
let mimetype = lookup(fileExtension)
8996

90-
if (mimetype === false) {
97+
if (!mimetype) {
9198
console.log(
9299
chalk`{yellow Unable to find mime-type for file of type {reset ${fileExtension}}!}`
93100
)

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"incremental": true,
4-
"target": "es5",
4+
"target": "ES2018",
55
"module": "commonjs",
66
"allowJs": true,
77
"declaration": true,

0 commit comments

Comments
 (0)