Skip to content

Commit

Permalink
Parametrizing app by its location (host's URL)
Browse files Browse the repository at this point in the history
Used for authorization re-directs.
  • Loading branch information
akoprow committed Feb 13, 2012
1 parent d8d4aca commit fc18f23
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -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)
Expand Down
37 changes: 37 additions & 0 deletions src/config.opa
@@ -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)
}

}
2 changes: 1 addition & 1 deletion src/facebook.opa
Expand Up @@ -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 }
Expand Down

0 comments on commit fc18f23

Please sign in to comment.