diff --git a/404.html b/404.html
new file mode 100644
index 000000000..0c6594404
--- /dev/null
+++ b/404.html
@@ -0,0 +1,49 @@
+
+
+
+
+
+ Single Page Apps for GitHub Pages
+
+
+
+ 404
+
+
diff --git a/index.html b/index.html
index 19e6e0fa6..17331f7dd 100644
--- a/index.html
+++ b/index.html
@@ -20,6 +20,34 @@
width: auto !important;
}
+
+
+
+
+
@@ -35,6 +63,8 @@
// Docsify configuration
window.$docsify = {
+ routerMode: 'history',
+ externalLinkTarget: '_self',
alias: {
'.*?/awesome':
'https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md',
diff --git a/server.js b/server.js
index 2ba6c0439..0b9dabc41 100644
--- a/server.js
+++ b/server.js
@@ -1,3 +1,5 @@
+const fs = require('fs');
+const path = require('path');
const liveServer = require('live-server')
const isSSR = !!process.env.SSR
const middleware = []
@@ -46,10 +48,30 @@ if (isSSR) {
})
}
+// emulate default behavior of GitHub Pages and other static servers that
+// serve a 404.html page when files are not found.
+middleware.push(
+ /**
+ * @param {import('http').IncomingMessage} req
+ * @param {import('http').ServerResponse} res
+ * @param {(error?: Error) => void} res
+ */
+ function (req, res, next) {
+ if (!fs.existsSync(path.resolve('.' + req.url))) {
+ console.log(res.statusCode = 404)
+ }
+ next();
+ }
+)
+
const params = {
port: 3000,
watch: ['lib', 'docs', 'themes'],
- middleware
+ middleware,
+
+ // emulate default behavior of GitHub Pages and other static servers that
+ // serve a 404.html page when files are not found.
+ file: '404.html',
}
liveServer.start(params)
diff --git a/vercel.json b/vercel.json
new file mode 100644
index 000000000..0f32683a9
--- /dev/null
+++ b/vercel.json
@@ -0,0 +1,3 @@
+{
+ "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
+}