mod_candy/mod_candy.lua
author Florian Zeitz <florob@babelmonkeys.de>
Sat, 06 Apr 2013 21:39:20 +0200
changeset 969 8eba9d4809d2
parent 933 5a975ba6a845
child 1031 6b34cc81e15d
permissions -rw-r--r--
mod_websocket: Set status_code instead of status
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
933
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     1
-- mod_candy.lua
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     2
-- Copyright (C) 2013 Kim Alvefur
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     3
--
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     4
-- Run this in www_files
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     5
-- curl -L http://github.com/candy-chat/candy/tarball/master | tar xzfv - --strip-components=1
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     6
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     7
local json_encode = require"util.json".encode;
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     8
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     9
local serve = module:depends"http_files".serve;
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    10
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    11
module:provides("http", {
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    12
	route = {
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    13
		["GET /prosody.js"] = function(event)
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    14
			event.response.headers.content_type = "text/javascript";
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    15
			return ("// Generated by Prosody\n"
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    16
				.."var Prosody = %s;\n")
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    17
					:format(json_encode({
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    18
						bosh_path = module:http_url("bosh","/http-bind");
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    19
						version = prosody.version;
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    20
						host = module:get_host();
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    21
						anonymous = module:get_option_string("authentication") == "anonymous";
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    22
					}));
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    23
		end;
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    24
		["GET /*"] = serve(module:get_directory().."/www_files");
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    25
	}
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    26
});
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    27