Skip to content

Commit 2aaf31b

Browse files
MachinisteWebposva
authored andcommitted
[Doc EN] — history-mode.md — Add Node.js Native Usage (#1596)
* Remove unnecessary new line Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Update dev * Add native Node.js server configuration Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Remove `;` and add `const` like other code examples. Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Remove more ";" Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Arrow function style added Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com> * Update history-mode.md
1 parent c16ff17 commit 2aaf31b

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

docs/en/essentials/history-mode.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,31 @@ location / {
4040
}
4141
```
4242

43-
#### Node.js (Express)
43+
#### Native Node.js
44+
45+
```js
46+
const http = require("http")
47+
const fs = require("fs")
48+
const httpPort = 80
49+
50+
http.createServer((req, res) => {
51+
fs.readFile("index.htm", "utf-8", (err, content) => {
52+
if (err) {
53+
console.log('We cannot open "index.htm" file.')
54+
}
55+
56+
res.writeHead(200, {
57+
"Content-Type": "text/html; charset=utf-8"
58+
})
59+
60+
res.end(content)
61+
})
62+
}).listen(httpPort, () => {
63+
console.log("Server listening on: http://localhost:%s", httpPort)
64+
})
65+
```
66+
67+
#### Express with Node.js
4468

4569
For Node.js/Express, consider using [connect-history-api-fallback middleware](https://github.com/bripkens/connect-history-api-fallback).
4670

@@ -95,4 +119,4 @@ const router = new VueRouter({
95119
})
96120
```
97121

98-
Alternatively, if you are using a Node.js server, you can implement the fallback by using the router on the server side to match the incoming URL and respond with 404 if no route is matched.
122+
Alternatively, if you are using a Node.js server, you can implement the fallback by using the router on the server side to match the incoming URL and respond with 404 if no route is matched. Check out the [Vue server side rendering documentation](https://ssr.vuejs.org/en/) for more information.

0 commit comments

Comments
 (0)