Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: example is added with a server written in Go #2962

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs-gitbook/de/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ location / {

Für Node.js/Express benutz du am besten [connect-history-api-fallback middleware](https://github.com/bripkens/connect-history-api-fallback).

#### Golang (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
var folder = "./"

func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(folder + r.URL.Path); err != nil {
http.ServeFile(w, r, folder+"/index.html")
return
}
http.ServeFile(w, r, folder+r.URL.Path)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```

## Warnung

Es gibt einen kleinen Nachteil: Der Server wird keine 404-Fehler mehr melden, da alle nicht gefundenen Pfade zur `index.html` führen. Um das zu beheben, solltest du eine Sammel-Route in der Vue-App für die 404-Seite definieren.
Expand Down
28 changes: 27 additions & 1 deletion docs-gitbook/es/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,36 @@ location / {
}
```

#### Node.js (Express)
#### Node.js utilizando (Express)

Para Node.js/Express, considera utilizar el middleware [connect-history-api-fallback](https://github.com/bripkens/connect-history-api-fallback).

#### Golang utilizando (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```

## Deventajas

Hay una deventaja para esto: tu servidor ya no reportará errores 404 dado que todas las rutas no encontradas serán redireccionadas al archivo `index.html`. Para solucionar este problema debes implementar dentro de la aplicación Vue una ruta por defecto para mostrar una página de error 404:
Expand Down
27 changes: 27 additions & 0 deletions docs-gitbook/fr/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ http.createServer((req, res) => {

Pour Node.js avec Express, vous pouvez utiliser le [middleware connect-history-api-fallback](https://github.com/bripkens/connect-history-api-fallback).


#### Golang avec (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```

#### Internet Information Services (IIS)

1. Instaler [IIS UrlRewrite](https://www.iis.net/downloads/microsoft/url-rewrite)
Expand Down
28 changes: 28 additions & 0 deletions docs-gitbook/ja/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ http.createServer((req, res) => {

Node.js/Express では [connect-history-api-fallback middleware](https://github.com/bripkens/connect-history-api-fallback) の利用を検討してください。


#### Golang (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```


#### Internet Information Services (IIS)

1. [IIS UrlRewrite](https://www.iis.net/downloads/microsoft/url-rewrite) をインストール
Expand Down
27 changes: 27 additions & 0 deletions docs-gitbook/kr/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,33 @@ http.createServer((req, res) => {

Node.js/Express의 경우 [connect-history-api-fallback 미들웨어](https://github.com/bripkens/connect-history-api-fallback)를 고려해보세요.

#### Golang (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```


#### Internet Information Services (IIS)

```
Expand Down
27 changes: 27 additions & 0 deletions docs-gitbook/ru/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ http.createServer((req, res) => {

При использовании Node.js/Express, мы рекомендуем пользоваться [connect-history-api-fallback middleware](https://github.com/bripkens/connect-history-api-fallback).


#### Golang использованием (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```

#### Internet Information Services (IIS)

1. Установить [IIS UrlRewrite](https://www.iis.net/downloads/microsoft/url-rewrite)
Expand Down
26 changes: 26 additions & 0 deletions docs/fr/guide/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@ http.createServer((req, res) => {

Pour Node.js avec Express, vous pouvez utiliser le [middleware connect-history-api-fallback](https://github.com/bripkens/connect-history-api-fallback).

#### Golang avec (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```

### Internet Information Services (IIS)

1. Instaler [IIS UrlRewrite](https://www.iis.net/downloads/microsoft/url-rewrite)
Expand Down
27 changes: 27 additions & 0 deletions docs/guide/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ http.createServer((req, res) => {

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


#### Golang with (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```

#### Internet Information Services (IIS)

1. Install [IIS UrlRewrite](https://www.iis.net/downloads/microsoft/url-rewrite)
Expand Down
27 changes: 27 additions & 0 deletions docs/ja/guide/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ http.createServer((req, res) => {

Node.js/Express では [connect-history-api-fallback middleware](https://github.com/bripkens/connect-history-api-fallback) の利用を検討してください。


#### Golang (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```

#### Internet Information Services (IIS)

1. [IIS UrlRewrite](https://www.iis.net/downloads/microsoft/url-rewrite) をインストール
Expand Down
27 changes: 27 additions & 0 deletions docs/kr/guide/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,33 @@ http.createServer((req, res) => {

Node.js/Express의 경우 [connect-history-api-fallback 미들웨어](https://github.com/bripkens/connect-history-api-fallback)를 고려해보세요.


#### (gorilla/mux)와 Golang

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```

#### Internet Information Services (IIS)

```
Expand Down
27 changes: 27 additions & 0 deletions docs/ru/guide/essentials/history-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ http.createServer((req, res) => {

При использовании Node.js/Express, мы рекомендуем пользоваться [connect-history-api-fallback middleware](https://github.com/bripkens/connect-history-api-fallback).


#### Golang использованием (gorilla/mux)

```go
package main
import (
"net/http"
"os"
"github.com/gorilla/mux"
)
var httpPort = "80"
var indexFile = "index.html"
func serverHandler(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(indexFile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.ServeFile(w, r, indexFile)
}
func main() {
r := mux.NewRouter()
r.NotFoundHandler = r.NewRoute().HandlerFunc(serverHandler).GetHandler()
http.Handle("/", r)
http.ListenAndServe(":"+httpPort, nil)
}
```

#### Internet Information Services (IIS)

1. Установить [IIS UrlRewrite](https://www.iis.net/downloads/microsoft/url-rewrite)
Expand Down
Loading