-
Notifications
You must be signed in to change notification settings - Fork 15
/
chat.psgi
70 lines (51 loc) · 1.98 KB
/
chat.psgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use strict;
use warnings;
use utf8;
use FindBin;
use lib ("$FindBin::Bin/lib");
my $root;
BEGIN {
use File::Basename ();
use File::Spec ();
$root = File::Basename::dirname(__FILE__);
$root = File::Spec->rel2abs($root);
unshift @INC, "$root/lib";
}
use File::Spec;
use File::Basename 'dirname';
use Plack::Builder;
use Plack::Middleware::Static;
use Plack::App::File;
use Plack::Session;
use lib ("$FindBin::Bin/lib", "$FindBin::Bin/extlib/lib/perl5");
use PocketIO;
use Yancha;
use Yancha::Web;
use Yancha::DataStorage::DBI;
use Yancha::Config::Simple;
my $config = Yancha::Config::Simple->load_file( $ENV{ YANCHA_CONFIG_FILE } || "$root/config.pl" );
my $data_storage = Yancha::DataStorage::DBI->connect(
connect_info => $config->{ database }->{ connect_info },
on_connect_exec => $config->{ database }->{ on_connect_exec }
);
my $yancha = Yancha->new( config => $config, data_storage => $data_storage );
builder {
enable 'Session';
enable "SimpleLogger", level => 'debug';
enable 'Plack::Middleware::Static',
root => $root,
path => qr{^/static/};
enable 'Plack::Middleware::Static',
path => qr{^(?:/robots\.txt|/favicon\.ico|/apple-touch-icon\.png)$},
root => File::Spec->catdir($root, 'static');
mount '/socket.io/socket.io.js' =>
Plack::App::File->new(file => File::Spec->catfile($root, 'static', 'socket.io.js'));
mount '/socket.io/static/flashsocket/WebSocketMain.swf' =>
Plack::App::File->new(file => File::Spec->catfile($root, 'static', 'WebSocketMain.swf'));
mount '/socket.io/static/flashsocket/WebSocketMainInsecure.swf' =>
Plack::App::File->new(file => File::Spec->catfile($root, 'static', 'WebSocketMainInsecure.swf'));
mount '/socket.io' => PocketIO->new( socketio => $config->{ socketio }, instance => $yancha );
$yancha->build_psgi_endpoint_from_server_info('api');
$yancha->build_psgi_endpoint_from_server_info('auth');
mount '/' => Yancha::Web->run(%$config);
}