Skip to content
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
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ go get -u github.com/ddo/go-vue-handler

* build vue app to get ``index.html`` and ``dist`` folder
* serve it as a static folder with go server
* all the static files must has extension

## example

Expand Down Expand Up @@ -46,4 +45,24 @@ func main() {
err := server.ListenAndServe()
panic(err)
}
```
```

## caveat

> Your server will no longer report 404 errors as all not-found paths now serve up your `index.html`
> file. To get around the issue, you should implement a catch-all route within your Vue app to show
> a 404 page:
>
> ```js
> const router = new VueRouter({
> mode: 'history',
> routes: [
> { path: '*', component: NotFoundComponent }
> ]
> })
> ```
>

https://router.vuejs.org/guide/essentials/history-mode.html#caveat

In addition, `go-vue-handler` tries to analyze HTTP Accept header, so if the browser expects to see an HTML5 page (mime type is `text/html`) it will receive `index.html` contents, otherwise - 404 status code.
22 changes: 21 additions & 1 deletion test/public/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>test</title><link href=/static/css/app.8a2065fc6ff38e2d0ec0c0e3509637eb.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.2ae2e69a05c33dfc65f8.js></script><script type=text/javascript src=/static/js/vendor.7fed9fa7b7ba482410b7.js></script><script type=text/javascript src=/static/js/app.bef432c284d1df839809.js></script></body></html>
<!DOCTYPE html>
<html>
<head>
<title>go-vue-handler</title>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-router"></script>
</head>
<body>
<div id="app">
<h1>Hello App!</h1>
<p>
<router-link to="/foo">Go to Foo</router-link>
<router-link to="/bar">Go to Bar</router-link>
<router-link to="/foo.bar">Go to Foo.Bar</router-link>
<router-link to="/bad/route">Go to Bad Route</router-link>
</p>
<router-view></router-view>
</div>
<script src="/js/app.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions test/public/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const FooBar = { template: '<div>foo.bar</div>' }
const PageNotFound = { template: '<h2>404 - Page Not Found</h2>' }
const routes = [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar },
{ path: '/foo.bar', component: FooBar },
{ path: '*', component: PageNotFound },
]
const router = new VueRouter({
mode: 'history',
routes: routes
})

var app = new Vue({
el: '#app',
router: router,
data: {
message: 'Hello Vue!'
}
})

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions test/public/static/js/app.bef432c284d1df839809.js

This file was deleted.

1 change: 0 additions & 1 deletion test/public/static/js/app.bef432c284d1df839809.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions test/public/static/js/manifest.2ae2e69a05c33dfc65f8.js

This file was deleted.

Loading