Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use Mojolicious::Lite;
- use strict;
- # CORS
- options '*' => sub {
- my $self = shift;
- # FIXME: use a domain from config
- $self->res->headers->header('Access-Control-Allow-Origin'=> 'http://localhost:7000');
- $self->res->headers->header('Access-Control-Allow-Credentials' => 'true');
- $self->res->headers->header('Access-Control-Allow-Methods' => 'GET, OPTIONS, POST, DELETE, PUT');
- $self->res->headers->header('Access-Control-Allow-Headers' => 'Content-Type, X-CSRF-Token');
- $self->res->headers->header('Access-Control-Max-Age' => '1728000');
- $self->respond_to(any => { data => '', status => 200 });
- };
- post '/auth' => sub {
- my $self = shift;
- my $login = $self->param('login') || '';
- my $passwd = $self->param('passwd') || '';
- $self->app->log->debug($login);
- $self->app->log->debug($passwd);
- my $json;
- my $status;
- if ($login eq 'a@a.com' && $passwd eq '123') {
- $json = { token => '123456' };
- $status = 201;
- } else {
- $json = { error => 'Unauthorized: Wrong login and password.' };
- $status = 401;
- }
- $self->respond_to(json => { json => $json, status => $status });
- };
- app->start;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement