Permalink
Browse files

Parametrizing app by its location (host's URL)

Used for authorization re-directs.
  • Loading branch information...
1 parent d8d4aca commit fc18f23a942fc2116a143840fefcc5fba80173c0 @akoprow akoprow committed Feb 2, 2012
Showing with 39 additions and 2 deletions.
  1. +1 −1 Makefile
  2. +37 −0 src/config.opa
  3. +1 −1 src/facebook.opa
View
@@ -1,6 +1,6 @@
NAME = webshell.exe
-SRC = parser.opa editor.opa webshell.opa login.opa facebook.opa serach.opa dropbox.opa
+SRC = parser.opa editor.opa webshell.opa login.opa facebook.opa search.opa dropbox.opa config.opa
SRCS = $(SRC:%=src/%)
all: $(NAME)
View
@@ -0,0 +1,37 @@
+// license: AGPL
+// (c) MLstate, 2011, 2012
+// author: Adam Koprowski
+
+database string /host
+
+module Config {
+
+ // TODO: abstract away this pattern
+ server host =
+ _ = CommandLine.filter(
+ { init: void
+ , parsers: [{ CommandLine.default_parser with
+ names: ["--host"],
+ param_doc: "HOST",
+ description: "Sets the address of the application (needed for all redirects)",
+ function on_param(state) {
+ parser host=(.*) ->
+ {
+ /host <- Text.to_string(host)
+ {no_params: state}
+ }
+ }
+ }]
+ , anonymous: []
+ , title: "General options"
+ }
+ )
+ match (?/host) {
+ case {some: host}: host
+ default:
+ Log.error("webshell[config]", "Cannot read host configuration
+Please re-run your application with: --host option")
+ System.exit(1)
+ }
+
+}
View
@@ -46,7 +46,7 @@ Please re-run your application with: --fb-config option")
private FBA = FbAuth(config)
private FBG = FbGraph
- private redirect = "http://webshell.tutorials.opalang.org/connect"
+ private redirect = "http://{Config.host}/connect/facebook"
private function get_fb_name(token) {
opts = { FBG.Read.default_object with token:token.token }

0 comments on commit fc18f23

Please sign in to comment.