Software /
code /
prosody-modules
Annotate
mod_candy/mod_candy.lua @ 2259:e0808be13d77
mod_cloud_notify: Abort and return error if unable to read storage to prevent loss of existing but unreachable data
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 28 Jul 2016 12:36:59 +0200 |
parent | 1864:991a5f74f848 |
child | 2440:7814a5c7fee8 |
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 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
|
5 |
1031
6b34cc81e15d
mod_candy: Add dependency on mod_bosh
Kim Alvefur <zash@zash.se>
parents:
933
diff
changeset
|
6 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
|
7 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
|
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 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
|
10 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
|
11 ["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
|
12 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
|
13 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
|
14 .."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
|
15 :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
|
16 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
|
17 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
|
18 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
|
19 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
|
20 })); |
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 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
|
22 ["GET /*"] = serve(module:get_directory().."/www_files"); |
1384
f67eacb1ac9f
mod_candy: Redirect from /candy -> /candy/
Kim Alvefur <zash@zash.se>
parents:
1031
diff
changeset
|
23 GET = function(event) |
f67eacb1ac9f
mod_candy: Redirect from /candy -> /candy/
Kim Alvefur <zash@zash.se>
parents:
1031
diff
changeset
|
24 event.response.headers.location = event.request.path.."/"; |
f67eacb1ac9f
mod_candy: Redirect from /candy -> /candy/
Kim Alvefur <zash@zash.se>
parents:
1031
diff
changeset
|
25 return 301; |
f67eacb1ac9f
mod_candy: Redirect from /candy -> /candy/
Kim Alvefur <zash@zash.se>
parents:
1031
diff
changeset
|
26 end; |
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
|
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 }); |
5a975ba6a845
mod_candy: Example of how easy it is to serve files from a prosody module
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 |