Comments (12)
Hi,
You could server static files easily, you must set with https://godoc.org/github.com/savsgio/atreugo#Router.Static with this default configuration (IndexName == "index.html", GenerateIndexPages == true, AcceptByteRange == true)
You could make a PR to adds config support.
from atreugo.
Example:
config := &atreugo.Config{
Host: "0.0.0.0",
Port: 8000,
}
server := atreugo.New(config)
server.Static("/static", "/var/www/html")
err := server.ListenAndServe()
if err != nil {
panic(err)
}
from atreugo.
I have seen godoc of atreugo about Static and ServeFile
I wish:
config := &atreugo.Config{
Host: "0.0.0.0",
Port: 8000,
Compress: true,
FS: &atreugo.FSConfig{
IndexName: "index.m3u8",
GenerateIndexPages: false,
AcceptByteRange: false,
},
}
server := atreugo.New(config)
server.Static("/static", "/var/www/html")
err := server.ListenAndServe()
if err != nil {
panic(err)
}
But now, I can only use the ugly code below to achieve:
fs := &fasthttp.FS{
Root: "/static",
IndexNames: []string{"index.m3u8"},
GenerateIndexPages: false,
AcceptByteRange: false,
}
fsHandler := fs.NewRequestHandler()
server.Path("GET", "/", func(ctx *atreugo.RequestCtx) error {
fsHandler(ctx.RequestCtx)
return nil
})
Or use FileResponse to implement the requirements of IndexNames
from atreugo.
Ok, I will add it soon!
from atreugo.
But one question, Do you need to serve just index.m3u8
or everything there in root directory?
from atreugo.
Because you could use ServeFile, to serve just one file
myserver.ServeFile("/static/index.m3u8", "/var/www/html/index.m3u8")
If you use ctx.FileResponse(...)
, the file will download.
from atreugo.
Thank you very much for your response.
This project needs set IndexNames to index.m3u8. I just wish set FS value in one config, Because this allows me to quickly know the configuration of the server.
In the atreugo/consts.go , I see const network = "tcp4" , I need listen on ipv4 and ipv6 . Can you add a setting item in config to set tcp, tcp4, tcp6?
from atreugo.
I know atreugo from the fasthttp README.md page, Atreugo is a great web framework.
It's build on top of fasthttp, I hope atreugo helps developers set the parameters of fasthttp.
If the framework solidifies a part of the http parameter, Then developers can only make adjustments around the framework to meet project needs.
from atreugo.
Ok, i know it. I will try to add static files configuration soon.
About serve tcp4 or tcp6. By default, if you use myserver.ListenAndServe()
, serves tcp4 connections, but if you need tcp6, you could create your own listener and use it with myserver.Serve(myListener)
or myserver.ServeGracefully(myListener)
https://godoc.org/github.com/savsgio/atreugo#Atreugo.Serve.
But I think it's a good idea to add some setting to configure the kind of connections such as tcp, tcp4 or tcp6 easily
from atreugo.
I know atreugo from the fasthttp README.md page, Atreugo is a great web framework.
It's build on top of fasthttp, I hope atreugo helps developers set the parameters of fasthttp.
If the framework solidifies a part of the http parameter, Then developers can only make adjustments around the framework to meet project needs.
Thank you so much, my purpose it that.
So, I feel happy because the developers lets me know how i can improve the framework to makes their life easy hehe, and they and you use it.
from atreugo.
I've just added StaticCustom. Now you could serve files with your own configuration.
In a few days, i will release a new version 😄
from atreugo.
And you could set the kind of listener you want, with the Network
option in configuration
from atreugo.
Related Issues (20)
- Possible breaking change in patch version? "path must begin with '/' in path ''" HOT 2
- AttachContext overrides previous AttachContext HOT 2
- Hi, Savsgio, how to add CORS middleware? HOT 30
- Is it possible to run "after" middleware even when "before" middleware exits error? HOT 5
- Unable to match URL with "/" ending HOT 1
- Unsupported path parameters with root / prefix HOT 1
- Problem with trailing "/" when optional url param is empty (11 version) - 308 redirect HOT 3
- I can not install HOT 1
- Error! installing with go get github.com/savsgio/atreugo HOT 5
- Cannot update/download deps HOT 1
- any sort of html template kind of real life example code to go with? router with html hello world at least HOT 1
- Instrumenting servers / paths to add metrics doesn't work when view returns an error HOT 1
- Use atreugo and autocert HOT 2
- Support custom logger HOT 4
- Possible race condition in context propagation HOT 3
- rate limit middleware request HOT 3
- Race condition when calling RequestCtx.Value() HOT 4
- Sentry APM Middleware HOT 1
- Occasional panic HOT 1
- Configurable JSON Marshaller HOT 2
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 atreugo.