forked from reactjs/react-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request reactjs#90 from dnmfarrell/master
Tutorial server in Perl, with example start code
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This file provided by Facebook is for non-commercial testing and evaluation | ||
# purposes only. Facebook reserves all rights not expressly granted. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
# FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
use Mojolicious::Lite; | ||
use Mojo::JSON qw(encode_json decode_json); | ||
|
||
app->static->paths->[0] = './public'; | ||
|
||
any '/' => sub { $_[0]->reply->static('index.html') }; | ||
|
||
any [qw(GET POST)] => '/api/comments' => sub { | ||
my $self = shift; | ||
my $comments = decode_json (do { local(@ARGV,$/) = 'comments.json';<> }); | ||
|
||
if ($self->req->method eq 'POST') | ||
{ | ||
push @$comments, { | ||
author => $self->param('author'), | ||
text => $self->param('text'), | ||
}; | ||
open my $FILE, '>', 'comments.json'; | ||
print $FILE encode_json($comments); | ||
} | ||
$self->render(json => $comments); | ||
}; | ||
my $port = $ENV{PORT} || 3000; | ||
app->start('daemon', '-l', "http://*:$port"); |