Commit e315a447 authored by Xavier Guimard's avatar Xavier Guimard

Change JS access (#1137)

parent 7a71c9db
......@@ -203,6 +203,30 @@ sub _mustBeDefined {
sub handler { _mustBeDefined(@_) }
sub sendJs {
my ( $self, $req ) = @_;
my $sp = $self->staticPrefix;
$sp =~ s/\/*$/\//;
my $sc = $req->script_name;
$sc = '.' unless ($sc);
$sc =~ s#/*$#/#;
my $s =
sprintf 'var staticPrefix="%s";'
. 'var scriptname="%s";'
. 'var availableLanguages="%s".split(/[,;] */);'
. 'var portal="%s";', $sp, $sc, $self->languages, $self->portal;
$s .= $self->javascript($req) if ( $self->can('javascript') );
return [
200,
[
'Content-Type' => 'application/javascript',
'Content-Length' => length($s),
'Cache-Control' => 'max-age=2592000',
],
[$s]
];
}
sub sendHtml {
my ( $self, $req, $template, %args ) = @_;
my $sp = $self->staticPrefix;
......@@ -210,22 +234,6 @@ sub sendHtml {
my $sc = $req->script_name;
$sc = '.' unless ($sc);
$sc =~ s#/*$#/#;
if ( defined $req->param('js') ) {
my $s =
sprintf 'var staticPrefix="%s";'
. 'var scriptname="%s";'
. 'var availableLanguages="%s".split(/[,;] */);'
. 'var portal="%s";', $sp, $sc, $self->languages, $self->portal;
$s .= $self->javascript($req) if ( $self->can('javascript') );
return [
200,
[
'Content-Type' => 'application/javascript',
'Content-Length' => length($s)
],
[$s]
];
}
$args{code} ||= 200;
$args{headers} ||= $req->respHeaders || [];
my $htpl;
......
......@@ -70,7 +70,8 @@ sub init {
}
}
return 0 unless (@working);
$self->addRoute( links => 'links', ['GET'] );
$self->addRoute( links => 'links', ['GET'] );
$self->addRoute( 'psgi.js' => 'sendJs', ['GET'] );
$self->defaultRoute( $working[0]->defaultRoute );
......
......@@ -19,7 +19,7 @@
<!-- Constants -->
<script type="text/JavaScript" src="<TMPL_VAR NAME="SCRIPTNAME">?js"></script>
<script type="text/JavaScript" src="<TMPL_VAR NAME="SCRIPTNAME">/psgi.js"></script>
<!-- //if:usedebianlibs
<script type="text/javascript" src="/javascript/jquery/jquery.min.js"></script>
......
......@@ -105,6 +105,10 @@ sub init {
->addAuthRoute( '*' => 'authenticatedRequest', ['GET'] )
->addAuthRoute( '*' => 'postAuthenticatedRequest', ['POST'] )
# psgi.js
->addUnauthRoute( 'psgi.js' => 'sendJs', ['GET'] )
->addAuthRoute( 'psgi.js' => 'sendJs', ['GET'] )
# Core REST API
->addUnauthRoute( ping => 'pleaseAuth', ['GET'] )
->addAuthRoute( ping => 'authenticated', ['GET'] )
......
......@@ -7,7 +7,7 @@
</div>
<!-- Constants -->
<script type="text/JavaScript" src="<TMPL_VAR NAME="SCRIPTNAME">?js"></script>
<script type="text/JavaScript" src="<TMPL_VAR NAME="SCRIPTNAME">/psgi.js"></script>
</body>
</html>
......@@ -3,7 +3,7 @@
</div>
<!-- Constants -->
<script type="text/JavaScript" src="<TMPL_VAR NAME="SCRIPTNAME">?js"></script>
<script type="text/JavaScript" src="<TMPL_VAR NAME="SCRIPTNAME">/psgi.js"></script>
</body>
</html>
<div id="footer"><TMPL_INCLUDE NAME="customfooter.tpl"></div>
</div><!-- end div "page" -->
<!-- Constants -->
<script type="text/JavaScript" src="<TMPL_VAR NAME="SCRIPTNAME">?js"></script>
<script type="text/JavaScript" src="<TMPL_VAR NAME="SCRIPTNAME">/psgi.js"></script>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment