예제 #1
0
파일: context.go 프로젝트: mattwkelly/rell
// Handler for /info/ to see a JSON view of some server context.
func Info(w http.ResponseWriter, r *http.Request) {
	context, err := context.FromRequest(r)
	if err != nil {
		view.Error(w, r, err)
		return
	}
	info := map[string]interface{}{
		"request": map[string]interface{}{
			"method": r.Method,
			"form":   r.Form,
			"url": map[string]interface{}{
				"path":  r.URL.Path,
				"query": r.URL.RawQuery,
			},
			"headers": headerMap(r.Header),
		},
		"context":    context,
		"pageTabURL": context.PageTabURL("/"),
		"canvasURL":  context.CanvasURL("/"),
		"sdkURL":     context.SdkURL(),
	}
	if version != "" {
		info["version"] = version
	}
	humanJSON(info, w, r)
}
예제 #2
0
파일: examples.go 프로젝트: mattwkelly/rell
func Raw(w http.ResponseWriter, r *http.Request) {
	context, example, err := parse(r)
	if err != nil {
		view.Error(w, r, err)
		return
	}
	if !example.AutoRun {
		view.Error(
			w, r, errors.New("Not allowed to view this example in raw mode."))
		return
	}
	service.Stats.Inc("viewed example in raw mode")
	view.Write(w, r, &exampleContent{
		Context: context,
		Example: example,
	})
}
예제 #3
0
파일: examples.go 프로젝트: mattwkelly/rell
func Saved(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" && r.URL.Path == savedPath {
		c, err := context.FromRequest(r)
		if err != nil {
			view.Error(w, r, err)
			return
		}
		if !xsrf.Validate(r.FormValue(paramName), w, r, savedPath) {
			service.Stats.Inc(savedPath + " xsrf failure")
			view.Error(w, r, errTokenMismatch)
			return
		}
		content := bytes.TrimSpace([]byte(r.FormValue("code")))
		content = bytes.Replace(content, []byte{13}, nil, -1) // remove CR
		id := examples.ContentID(content)
		db := examples.GetDB(c.Version)
		example, ok := db.Reverse[id]
		if ok {
			http.Redirect(w, r, c.ViewURL(example.URL), 302)
			return
		}
		err = exampleStore.Save(id, content)
		if err != nil {
			view.Error(w, r, err)
			return
		}
		service.Stats.Inc("saved example")
		http.Redirect(w, r, c.ViewURL(savedPath+id), 302)
		return
	} else {
		context, example, err := parse(r)
		if err != nil {
			view.Error(w, r, err)
			return
		}
		service.Stats.Inc("viewed saved example")
		view.Write(w, r, &page{
			Writer:  w,
			Request: r,
			Context: context,
			Example: example,
		})
	}
}
예제 #4
0
파일: examples.go 프로젝트: mattwkelly/rell
func Simple(w http.ResponseWriter, r *http.Request) {
	context, example, err := parse(r)
	if err != nil {
		view.Error(w, r, err)
		return
	}
	if !example.AutoRun {
		view.Error(
			w, r, errors.New("Not allowed to view this example in simple mode."))
		return
	}
	service.Stats.Inc("viewed example in simple mode")
	view.Write(w, r, &h.Document{
		Inner: &h.Frag{
			&h.Head{
				Inner: &h.Frag{
					&h.Meta{Charset: "utf-8"},
					&h.Title{h.String(example.Title)},
				},
			},
			&h.Body{
				Inner: &h.Frag{
					&loader.HTML{
						Resource: []loader.Resource{
							&fb.Init{
								AppID:      context.AppID,
								ChannelURL: context.ChannelURL(),
								URL:        context.SdkURL(),
							},
						},
					},
					&h.Div{
						ID: "example",
						Inner: &exampleContent{
							Context: context,
							Example: example,
						},
					},
				},
			},
		},
	})
}
예제 #5
0
파일: examples.go 프로젝트: mattwkelly/rell
func SdkChannel(w http.ResponseWriter, r *http.Request) {
	const maxAge = 31536000 // 1 year
	context, err := context.FromRequest(r)
	if err != nil {
		view.Error(w, r, err)
		return
	}
	service.Stats.Inc("viewed channel")
	w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", maxAge))
	view.Write(w, r, &h.Script{Src: context.SdkURL()})
}
예제 #6
0
파일: examples.go 프로젝트: mattwkelly/rell
func List(w http.ResponseWriter, r *http.Request) {
	context, err := context.FromRequest(r)
	if err != nil {
		view.Error(w, r, err)
		return
	}
	service.Stats.Inc("viewed examples listing")
	view.Write(w, r, &examplesList{
		Context: context,
		DB:      examples.GetDB(context.Version),
	})
}
예제 #7
0
파일: oauth.go 프로젝트: mattwkelly/rell
func Response(w http.ResponseWriter, r *http.Request) {
	c, err := context.FromRequest(r)
	if err != nil {
		view.Error(w, r, err)
		return
	}
	if r.FormValue("state") != state(w, r) {
		view.Error(w, r, errInvalidState)
		return
	}
	values := url.Values{}
	values.Set("client_id", strconv.FormatUint(fbapp.Default.ID(), 10))
	values.Set("client_secret", fbapp.Default.Secret())
	values.Set("redirect_uri", redirectURI(c))
	values.Set("code", r.FormValue("code"))
	res, err := fbapi.GetRaw("/oauth/access_token", values)
	if err != nil {
		view.Error(w, r, err)
		return
	}
	w.Write(res)
}
예제 #8
0
파일: examples.go 프로젝트: mattwkelly/rell
func Example(w http.ResponseWriter, r *http.Request) {
	context, example, err := parse(r)
	if err != nil {
		view.Error(w, r, err)
		return
	}
	service.Stats.Inc("viewed stock example")
	view.Write(w, r, &page{
		Writer:  w,
		Request: r,
		Context: context,
		Example: example,
	})
}
예제 #9
0
파일: oauth.go 프로젝트: mattwkelly/rell
func Start(w http.ResponseWriter, r *http.Request) {
	c, err := context.FromRequest(r)
	if err != nil {
		view.Error(w, r, err)
		return
	}
	values := url.Values{}
	values.Set("client_id", strconv.FormatUint(c.AppID, 10))
	if scope := r.FormValue("scope"); scope != "" {
		values.Set("scope", scope)
	}

	if c.ViewMode == context.Website {
		values.Set("redirect_uri", redirectURI(c))
		values.Set("state", state(w, r))
	} else {
		values.Set("redirect_uri", c.ViewURL("/auth/session"))
	}

	dialogURL := fburl.URL{
		Scheme:    "https",
		SubDomain: fburl.DWww,
		Env:       c.Env,
		Path:      "/dialog/oauth",
		Values:    values,
	}

	if c.ViewMode == context.Website {
		http.Redirect(w, r, dialogURL.String(), 302)
	} else {
		b, _ := json.Marshal(dialogURL.String())
		view.Write(w, r, &h.Script{
			Inner: h.Unsafe(fmt.Sprintf("top.location=%s", b)),
		})
	}
}
예제 #10
0
파일: web.go 프로젝트: chrisp-fb/rell
func (a *Handler) handleError(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) {
	a.Logger.Printf("Error at %s\n%s\n", r.URL, ctxerr.RichString(err))
	view.Error(w, r, a.Static, err)
}