Comments (4)
Hi @suntong, I will try to answer some of your questions:
- You could use templates to serve dynamic content, or go with the HTML5 push state model where you load your
index.html
on any request and do the routing on the client-side.
package main
import (
"log"
"github.com/gofiber/fiber"
)
func main() {
app := fiber.New()
// Static files .css .png .js
app.Static("/", "./public)
// Catch any route to serve index.html
app.Static("*", "./public/index.html)
log.Fatal(app.Listen(3000))
}
- Redirecting is really easy, see https://docs.gofiber.io/ctx#redirect
app.Get("/coffee", func(c *fiber.Ctx) {
c.Redirect("/teapot")
})
app.Get("/teapot", func(c *fiber.Ctx) {
c.Status(fiber.StatusTeapot).Send("🍵 short and stout 🍵")
})
If you have more questions, feel free to ask 👍
from boilerplate.
Oh, by "dynamic content", I meant merely contract to serve the static files as is -- the current /
, although served from a static files, is showing dynamic content on the user end. That's already what I'm asking for.
Just I don't know how a GET /user/:name/books/:title
handler can based itself from a static file (just like the existing static/public/index.html
). Using boilerplate as the example, I want to have a /usercard?userid=xx
paged, whose user info is display dynamically, while the whole look-and-feel, decoration etc are coming from a static .html file, to which if I make changes, will reflect on the user end without recompiling the go source code.
Just that I still haven't been able to wrap my head around how to do this part yet.
from boilerplate.
Previous question updated, and also,
- Serving dynamic content based on local static file. The key is the separation, I want to code my .html part in .html as much as possible, instead of writing them in .go. So far I am still not sure how to do it with gofiber, so would you provide a sample usage code please? I think the easiest way is to link each added user to a new
GET
page, where the dynamic content is served based on a local static user.html file.- Showcase of
redirect
. I want my/
page a redirect one, so that I can easily redirect to/v2/
if things are ready. So maybe renamestatic/public/index.html
asstatic/public/index-v1.html
and redirect to it from/
page?
I'm playing with your redirect example now. If I can get both parts work eventually, do you think it is a good idea to send in PR to showcase the above two features?
Thanks again for your considerations/helps.
from boilerplate.
Oh, by "dynamic content", I meant merely contract to serve the static files as is -- the current
/
, although served from a static files, is showing dynamic content on the user end. That's already what I'm asking for.Just I don't know how a
GET /user/:name/books/:title
handler can based itself from a static file (just like the existingstatic/public/index.html
). Using boilerplate as the example, I want to have a/usercard?userid=xx
paged, whose user info is display dynamically, while the whole look-and-feel, decoration etc are coming from a static .html file, to which if I make changes, will reflect on the user end without recompiling the go source code.Just that I still haven't been able to wrap my head around how to do this part yet.
Having read over the template project (UTSL) for the 3rd time, I kind of have an idea what should be done. The least difficult way for me seem to be using the template/html template engines, then setup layout templates so as to define the '/usercard' using html template.
Is it so? Is there any demo that I can reference to? thx
from boilerplate.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from boilerplate.