Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
3a9999ce6d | |||
f1aa34fc56 |
14
README.md
14
README.md
@ -45,11 +45,8 @@ In `/etc/nginx/dumpdom.conf`, paste this:
|
||||
|
||||
```
|
||||
map $http_user_agent $dumpdom_ua {
|
||||
|
||||
default 0;
|
||||
|
||||
"~Prerender" 0;
|
||||
|
||||
"~*googlebot" 1;
|
||||
"~*bingbot" 1;
|
||||
"~*yandex" 1;
|
||||
@ -133,10 +130,10 @@ server {
|
||||
if ($uri ~* "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)") {
|
||||
set $dumpdom 0;
|
||||
}
|
||||
if ($prerender = 1) {
|
||||
if ($dumpdom = 1) {
|
||||
proxy_pass http://127.0.0.1:9292;
|
||||
}
|
||||
if ($prerender = 0) {
|
||||
if ($dumpdom = 0) {
|
||||
rewrite .* /index.html break;
|
||||
}
|
||||
}
|
||||
@ -230,16 +227,13 @@ server {
|
||||
if ($args ~ "_escaped_fragment_") {
|
||||
set $dumpdom 1;
|
||||
}
|
||||
if ($http_user_agent ~ "Prerender") {
|
||||
set $dumpdom 0;
|
||||
}
|
||||
if ($uri ~* "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)") {
|
||||
set $dumpdom 0;
|
||||
}
|
||||
if ($prerender = 1) {
|
||||
if ($dumpdom = 1) {
|
||||
proxy_pass http://127.0.0.1:9292;
|
||||
}
|
||||
if ($prerender = 0) {
|
||||
if ($dumpdom = 0) {
|
||||
rewrite .* /index.html break;
|
||||
}
|
||||
}
|
||||
|
21
cmd/serve.go
21
cmd/serve.go
@ -16,7 +16,11 @@ limitations under the License.
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dalu/chromedom/server"
|
||||
@ -27,6 +31,7 @@ var (
|
||||
binary string
|
||||
duration time.Duration
|
||||
maxmem int
|
||||
addr string
|
||||
)
|
||||
|
||||
// serveCmd represents the serve command
|
||||
@ -38,13 +43,15 @@ var serveCmd = &cobra.Command{
|
||||
s := http.DefaultServeMux
|
||||
h := server.NewHandler(binary, duration, maxmem)
|
||||
s.Handle("/", h)
|
||||
return http.ListenAndServe(":9292", s)
|
||||
// return runUnix("/tmp/chromedom.sock", s)
|
||||
if strings.HasPrefix(addr, "unix:") {
|
||||
return runUnix(strings.TrimPrefix(addr, "unix:"), s)
|
||||
} else {
|
||||
fmt.Printf("Listening and serving HTTP on %s", addr)
|
||||
return http.ListenAndServe(addr, s)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
func runUnix(file string, engine *http.ServeMux) (err error) {
|
||||
fmt.Printf("Listening and serving HTTP on unix:/%s", file)
|
||||
os.Remove(file)
|
||||
@ -53,11 +60,12 @@ func runUnix(file string, engine *http.ServeMux) (err error) {
|
||||
return
|
||||
}
|
||||
defer listener.Close()
|
||||
os.Chmod(file, 0777)
|
||||
if err := os.Chmod(file, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
err = http.Serve(listener, engine)
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(serveCmd)
|
||||
@ -65,4 +73,5 @@ func init() {
|
||||
serveCmd.Flags().StringVarP(&binary, "binary", "b", "/usr/bin/google-chrome", "chrome, chromium or headless binary path")
|
||||
serveCmd.Flags().DurationVarP(&duration, "duration", "d", 60*time.Minute, "how long the values live in the cache")
|
||||
serveCmd.Flags().IntVarP(&maxmem, "maxmem", "m", 512, "maximum memory in MB the cache may use")
|
||||
serveCmd.Flags().StringVarP(&addr, "addr", "a", "localhost:9292", "ip:port pair to listen on, or prefixed with unix: the unix socket path to listen on")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user