| 165 | } |
| 166 | |
| 167 | func (s *Server) Start() { |
| 168 | s.c = cache.New(30*time.Minute, 1*time.Minute) |
| 169 | |
| 170 | ssrServer := http.NewServeMux() |
| 171 | ssrServer.HandleFunc("/", s.handleRender) |
| 172 | go http.ListenAndServe(":8687", ssrServer) |
| 173 | |
| 174 | l := launcher.New() |
| 175 | l.Set("no-sandbox") |
| 176 | headlessBrowserUrl := l.MustLaunch() |
| 177 | browser := rod.New().ControlURL(headlessBrowserUrl).MustConnect() |
| 178 | |
| 179 | svgServer := http.NewServeMux() |
| 180 | svgServer.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 181 | if len(r.URL.String()) > 2 { |
| 182 | if r.URL.String()[1] == '?' { |
| 183 | s.handleSVG(w, r, browser) |
| 184 | |
| 185 | return |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | http.NotFound(w, r) |
| 190 | }) |
| 191 | http.ListenAndServe(":8686", svgServer) |
| 192 | } |