annotate mod_candy/mod_candy.lua @ 1089:4057f176be7b

mod_s2soutinjection: Initial commit, variant of mod_srvinjection using 0.9+ APIs
author Kim Alvefur <zash@zash.se>
date Fri, 28 Jun 2013 03:20:57 +0200
parents 6b34cc81e15d
children f67eacb1ac9f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1031
6b34cc81e15d mod_candy: Add dependency on mod_bosh
Kim Alvefur <zash@zash.se>
parents: 933
diff changeset
9 module:depends"bosh";
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
10 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
11
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 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
13 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
14 ["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
15 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
16 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
17 .."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
18 :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
19 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
20 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
21 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
22 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
23 }));
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 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
25 ["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
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 });
5a975ba6a845 mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28