3 # Copyright (c) 2010 Abel Abraham Camarillo Ojeda <acamari@verlet.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 # PSGI entry point and configuration file.
19 # Please copy this file as 'Semece.psgi', and edit it!.
27 ######################
28 # USER CONFIGURATION #
29 ######################
31 # About filesystem paths.
33 # Absolute filesystem path to the current dir. (No default value)
35 # Absolute filesystem path to the data dir. (No default value)
37 # Absolute filesystem path to the user dir. (Default: /home/)
43 # Suffix for markdown files (default: ".mkd")
45 # Index file: file to parse when a user request the parent directory.
46 # (default: "index.mkd")
47 mkd_idx
=> "index.mkd",
48 # Markdown content type: default content-type for markdown.
49 mkd_ct
=> "text/plain; charset=UTF-8;",
50 # Content-Type for plain text: Content-Type header to show when we are
51 # returning plain text to the user. (default: "text/plain;
53 plain_ct
=> "text/plain; charset=UTF-8;",
54 # Content-Type for HTML: Content-Type header to show when we are
55 # returning HTML to the user. (default: "text/html; charset=UTF-8")
56 html_ct
=> "text/html; charset=UTF-8;",
57 # Fallback Content-Type: when I cannot determine which one to use.
58 fb_ct
=> "application/octect-stream",
61 # URI to filesystem resolution "table"; this _must_ be an array ref. We travel
62 # this array using it as a hash (getting a key and value pair (so this array ref
63 # _must_ have an even number of elements)). First, we match an URI against the
64 # "key" of this "hash", if it matches, then we look into the hash "value" (which
65 # must be a true hash ref) for a key named "fs" which declares an anonymous
66 # subroutine which is run with two arguments: the original URI, and the regex
67 # that matched it. You are free to implement your URI to filesystem translation
68 # however you like (but be sure to not insert any '..', or any other insecure
71 qr!^/static$|^/static/! => {
74 my ($uri, $regex) = @_;
75 return $conf->{srcd
}. $uri;
78 qr!^/~([[:alnum:]_]+)! => {
81 my ($uri, $regex) = @_;
82 my ($user) = $uri =~ $regex;
83 die "\$user mustn't be undef!, stopped"
86 return $conf->{userd
}. "/". $user.
87 "/". "public_html/". $uri;
93 my ($uri, $regex) = @_;
94 return $conf->{postd
}. "/". $uri;
107 if (not defined($conf->{srcd
})) {
108 die "ERROR: \$conf->{srcd} mustn't be undef!, stopped";
109 } elsif (not $conf->{srcd
}) {
110 die "ERROR: \$conf->{srcd} mustn't be empty!, stopped";
116 # Adds $conf->{srcd} to the search path for libraries, this must be done at
118 sub grow_inc
{unshift(@INC, $conf->{srcd
}. "/lib")}
119 BEGIN {$conf = checkconf
(setconf
()); grow_inc
();}
125 # XXX: The $conf set in the BEGIN is lost for unknown reasons...
129 $env->{"semece.conf"} = $conf;
130 return &Semece
::serv
($env);