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

Serve static files from root while serving dynamic routes as well #283

Open
xeoncross opened this issue Oct 21, 2019 · 0 comments
Open

Serve static files from root while serving dynamic routes as well #283

xeoncross opened this issue Oct 21, 2019 · 0 comments

Comments

@xeoncross
Copy link

Being able to serve static files at the root ("/index.html") while still allowing other routes is not covered by the readme. None of the issues I've read cover this either. I'm posting a working solution here for those looking. Perhaps this can be added to the readme.

router := httprouter.New()
router.GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	http.FileServer(http.Dir(("./templates"))).ServeHTTP(w, r)
})
router.GET("/api/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	...
})
http.ListenAndServe(":3000", router)

This solves the panic: '/api/' in new path '/api/' conflicts with existing wildcard '/*filepath' in existing prefix '/*filepath' error when using the recommended router.ServeFiles("/*filepath", http.Dir("./templates")) function.

similark pushed a commit to similarweb/httprouter that referenced this issue May 9, 2023
* swapping watch broadcaster channel behavior

Signed-off-by: Aaron Schlesinger <[email protected]>

* small test refactor

Signed-off-by: Aaron Schlesinger <[email protected]>

* more comments in test

Signed-off-by: Aaron Schlesinger <[email protected]>

* more comments and interface implementation check for fake deployment cache

Signed-off-by: Aaron Schlesinger <[email protected]>

* adding comment to closeableWatcher

Signed-off-by: Aaron Schlesinger <[email protected]>

* forgot the beginning of comment

Signed-off-by: Aaron Schlesinger <[email protected]>

* adding error checking to the closeableWatcher

Signed-off-by: Aaron Schlesinger <[email protected]>

* removing resultCalls from the closeable watcher

Signed-off-by: Aaron Schlesinger <[email protected]>

* removing the closeableWatcher in favor of the fake watcher functionality in client-go

Signed-off-by: Aaron Schlesinger <[email protected]>

* closeableWatcher => reopeningWatcher

The core functionality needed was automatic reopening of watch channels. This commit
implements that while removing some ancillary things like specifying whether
to reopen etc...

Signed-off-by: Aaron <[email protected]>

* fixing nil ptr exception

Signed-off-by: Aaron <[email protected]>

* clarifying comments

Signed-off-by: Aaron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant