Giter VIP home page Giter VIP logo

plack-pwa-api's Introduction

NAME

Plack Twiggy Product REST API

DESCRIPTION

This service provides the Product Data as REST API for the Plack Twiggy PWA Project.

To learn more about the Plack Twiggy PWA Project please visit: Plack Twiggy PWA

The running Version is hosted on Glitch at: Plack Twiggy Product REST API

REQUIREMENTS

To rebuild this web site the Minimum Requirements are to have Perl and cpanminus installed. The site uses the libraries Plack, Twiggy and JSON. The Twiggy Web Server requires the AnyEvent library. The Server Responses are provided completely as JSON documents. The API Data Structures are implemented with the Moose library for OO-Design.

INSTALLATION

  • cpanminus

    The cpanm Script will install the dependencies on local user level as they are found in the cpanfile. To run the installation call the cpanm Command within the project directory:

          cpanm -vn --installdeps .
    

EXECUTION

  • plackup

    The Site can be launched using the plackup Script as seen in the package.json. To launch the Site call the plackup Command within the project directory:

          plackup --server Twiggy --port 3000 scripts/web.psgi
    

IMPLEMENTATION

  • AnyEvent::Future

    To not block the server main thread too long and to enable asynchronous request processing the AnyEvent feature of Twiggy as AnyEvent::Future is used. Each Product Data Request produces a future that the Product Data Factory manages to build a complete Product Data List

plack-pwa-api's People

Contributors

bodo-hugo-barwich avatar

Watchers

 avatar

plack-pwa-api's Issues

Cache Pre-build fails in Testing Environment

When the API Image is deployed on an Environment where the user is different from the User in the Container the API is unable to use the hosted shared Directories:

pwa_api | Running Pre-Caching ...
pwa_api | Cache 'list-product-urls_-1_0': Set Cache failed with Exception [2]: 'No such file or directory'
pwa_api | Can't use string ("mkpath failed for cache/4: Permi"...) as a HASH ref while "strict refs" in use at /home/plack-pwa/scripts/../lib/Cache/Files.pm line 230.

the pre-build script produces an Exception which is not processed correctly.

Response for missing Cache Key

When the Product Data API Container is deployed on a new host system and the persistent cache directory is mounted into the Container the Cache Directory happens to be empty

$ docker-compose exec api bash
pwa1_web@93d18b5976ce:~$ pwd
/home/plack-pwa
pwa1_web@93d18b5976ce:~$ ls -lah
total 44K
drwxr-xr-x 1 pwa1_web web    30 Sep  4 10:29 .
drwxr-xr-x 1 root     root   23 Sep  4 10:29 ..
-rw-r--r-- 1 pwa1_web web   220 Aug 31  2015 .bash_logout
-rw-r--r-- 1 pwa1_web web  3.7K Aug 31  2015 .bashrc
drwxr-xr-x 8 root     root  177 Sep  4 10:27 .git
drwxr-xr-x 3 root     root   23 Sep  4 10:27 .github
-rw-r--r-- 1 root     root  135 Sep  4 10:27 .gitignore
-rw-r--r-- 1 root     root  395 Sep  4 10:27 .glitch-assets
-rw-r--r-- 1 pwa1_web web   655 Jul 12  2019 .profile
-rw-r--r-- 1 root     root 1.1K Sep  4 10:27 Dockerfile
-rw-r--r-- 1 root     root 2.2K Sep  4 10:27 README.md
-rw-r--r-- 1 root     root 2.2K Sep  4 10:27 README.pod
drwxr-xr-x 2 root     root   19 Sep  4 10:27 bin
drwxr-xr-x 2 pwa1_web web    19 Sep  4 11:42 cache
drwxr-xr-x 2 root     root   25 Sep  4 10:27 config
-rw-r--r-- 1 root     root  319 Sep  4 10:27 cpanfile
drwxr-xr-x 3 root     root   20 Sep  4 10:27 etc
drwxr-xr-x 2 root     root   92 Sep  4 10:27 images
drwxr-xr-x 4 root     root   68 Sep  4 10:27 lib
drwxr-xr-x 1 pwa1_web web    94 Sep  4 11:47 log
-rw-r--r-- 1 root     root   76 Sep  4 10:27 package-lock.json
-rw-r--r-- 1 root     root  961 Sep  4 10:27 package.json
drwxr-xr-x 1 pwa1_web web    28 Sep  4 11:47 perl5
drwxr-xr-x 2 root     root   44 Sep  4 10:27 scripts
drwxr-xr-x 2 root     root   31 Sep  4 10:27 t
pwa1_web@93d18b5976ce:~$ ls -lah cache
total 0
drwxr-xr-x 2 pwa1_web web 19 Sep  4 11:42 .
drwxr-xr-x 1 pwa1_web web 30 Sep  4 10:29 ..
-rw-r--r-- 1 pwa1_web web  0 Sep  4 11:42 .keep
pwa1_web@93d18b5976ce:~$ ls -lah scripts
total 16K
drwxr-xr-x 2 root     root   44 Sep  4 10:27 .
drwxr-xr-x 1 pwa1_web web    30 Sep  4 10:29 ..
-rwxr-xr-x 1 root     root 3.2K Sep  4 10:27 build_cache.pl
-rw-r--r-- 1 root     root 8.1K Sep  4 10:27 web.psgi

So the Product Data List Cache does not exist and returns an empty result which produces an Exception in the system:

pwa_api | req dmp:
pwa_api | bless({
pwa_api |   env => {
pwa_api |            "HTTP_ACCEPT"          => "*/*",
pwa_api |            "HTTP_ACCEPT_ENCODING" => "gzip, deflate",
pwa_api |            "HTTP_ACCEPT_LANGUAGE" => "es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3",
pwa_api |            "HTTP_CACHE_CONTROL"   => "no-cache",
pwa_api |            "HTTP_CONNECTION"      => "keep-alive",
pwa_api |            "HTTP_HOST"            => "localhost:3100",
pwa_api |            "HTTP_ORIGIN"          => "http://localhost:3000",
pwa_api |            "HTTP_PRAGMA"          => "no-cache",
pwa_api |            "HTTP_REFERER"         => "http://localhost:3000/",
pwa_api |            "HTTP_USER_AGENT"      => "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0",
pwa_api |            "PATH_INFO"            => "/coffees",
pwa_api |            "psgi.errors"          => *main::STDERR,
pwa_api |            "psgi.input"           => \*Twiggy::Server::$null_io,
pwa_api |            "psgi.multiprocess"    => "",
pwa_api |            "psgi.multithread"     => "",
pwa_api |            "psgi.nonblocking"     => 1,
pwa_api |            "psgi.run_once"        => "",
pwa_api |            "psgi.streaming"       => 1,
pwa_api |            "psgi.url_scheme"      => "http",
pwa_api |            "psgi.version"         => [1, 0],
pwa_api |            "psgix.input.buffered" => 1,
pwa_api |            "psgix.io"             => \*AnyEvent::Socket::$fh,
pwa_api |            "QUERY_STRING"         => "",
pwa_api |            "REMOTE_ADDR"          => "172.18.0.1",
pwa_api |            "REQUEST_METHOD"       => "GET",
pwa_api |            "REQUEST_URI"          => "/coffees",
pwa_api |            "SCRIPT_NAME"          => "",
pwa_api |            "SERVER_NAME"          => "0.0.0.0",
pwa_api |            "SERVER_PORT"          => 3000,
pwa_api |            "SERVER_PROTOCOL"      => "HTTP/1.1",
pwa_api |          },
pwa_api | }, "Plack::Request")
pwa_api | res dmp:
pwa_api | bless({
pwa_api |   headers => bless({
pwa_api |                "access-control-allow-origin" => ["*"],
pwa_api |                "connection" => ["close"],
pwa_api |                "content-security-policy" => [
pwa_api |                  "default-src 'self' localhost *.glitch.me; img-src *; style-src 'unsafe-inline'",
pwa_api |                ],
pwa_api |                "content-type" => "application/json",
pwa_api |              }, "HTTP::Headers::Fast"),
pwa_api |   status  => 200,
pwa_api | }, "Plack::Response")
pwa_api | 2021-09-05 11:26:54 : Request '/coffees' - Exception: Can't locate object method "result" via package "list-product-urls_-1_0" (perhaps you forgot to load "list-product-urls_-1_0"?) at /home/plack-pwa/scripts/../lib/Product/Factory.pm line 160.
pwa_api | 172.18.0.1 - - [05/Sep/2021:11:26:54 +0000] "GET /coffees HTTP/1.1" 500 - "http://localhost:3000/" "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0"
pwa_api | -:localhost:3100 (172.18.0.1,-) [2021-09-05:11:26:54] [154329] "Mime:application/json" "GET /coffees HTTP/1.1" 500 362 "http://localhost:3000/" "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0"

Configurable Environments

The Automated Tests with PhantomJS have shown that they can only succeed when the Product Data API runs on the same Host
as documented in : Automated Testing with PhantomJS

So the Product Data API needs to be run on localhost for testing. Probably in a Docker Environment.
There it needs to use a different Port as in the Glitch Production Environment.

Which results in the necessity to load different configurations for each environment and that the Application needs to recognize them correctly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.