package server import ( "fmt" "io" "local/router" "local/todo-server/config" "log" "net/http" "net/url" "os" "path" "path/filepath" ) func (s *Server) Routes() error { routes := []struct { path string handler http.HandlerFunc }{ { path: "/", handler: s.index, }, { path: "/mytinytodo_lang.php", handler: s.lang, }, { path: fmt.Sprintf("%s%s", router.Wildcard, router.Wildcard), handler: s.phpProxy, }, { path: "/ajax.php", handler: s.HandleAjax, }, /* { path: "db/index.html", handler: s.static, }, { path: "jquery/index.html", handler: s.static, }, { path: "lang/index.html", handler: s.static, }, { path: "themes/index.html", handler: s.static, }, { path: "tmp/index.html", handler: s.static, }, { path: "jquery/jquery-1.4.4.min.js", handler: s.static, }, { path: "jquery/jquery-ui-1.8.7.custom.min.js", handler: s.static, }, { path: "jquery/jquery.autocomplete-1.1.js", handler: s.static, }, { path: "mytinytodo.js", handler: s.static, }, { path: "mytinytodo_ajax_storage.js", handler: s.static, }, { path: "testdata/mytinytodo2/themes/default/pda.css", handler: s.static, }, { path: "testdata/mytinytodo2/themes/default/print.css", handler: s.static, }, { path: "testdata/mytinytodo2/themes/default/style.css", handler: s.static, }, { path: "testdata/mytinytodo2/themes/default/style_rtl.css", handler: s.static, }, */ } for _, route := range routes { if err := s.Add(route.path, route.handler); err != nil { return err } } return nil } func (s *Server) lang(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, ` mytinytodo.lang.init({ confirmDelete: "Are you sure you want to delete the task?", confirmLeave: "There can be unsaved data. Do you really want to leave?", actionNoteSave: "save", actionNoteCancel: "cancel", error: "Some error occurred (click for details)", denied: "Access denied", invalidpass: "Wrong password", tagfilter: "Tag:", addList: "Create new list", addListDefault: "Todo", renameList: "Rename list", deleteList: "This will delete current list with all tasks in it.\nAre you sure?", clearCompleted: "This will delete all completed tasks in the list.\nAre you sure?", settingsSaved: "Settings saved. Reloading...", daysMin: ["Su","Mo","Tu","We","Th","Fr","Sa"], daysLong: ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"], monthsLong: ["January","February","March","April","May","June","July","August","September","October","November","December"], tags: "Tags", tasks: "Tasks", f_past: "Overdue", f_today: "Today and tomorrow", f_soon: "Soon" }); `) } func (s *Server) index(w http.ResponseWriter, r *http.Request) { f, err := os.Open(path.Join(config.Root, "index.html")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } defer f.Close() io.Copy(w, f) } func (s *Server) phpProxy(w http.ResponseWriter, r *http.Request) { switch filepath.Ext(r.URL.Path) { case ".php": default: s.static(w, r) return } url, err := url.Parse(config.MyTinyTodo) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } else { log.Println("proxying", url.String(), r.URL.Path) //proxy := httputil.NewSingleHostReverseProxy(url) //proxy.ServeHTTP(w, r) } } func (s *Server) static(w http.ResponseWriter, r *http.Request) { s.fileServer.ServeHTTP(w, r) }