0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

plunkerでserviceworker その2

0
Posted at

概要

plunkerでserviceworker、やってみた。
codepenでは、出来ない。
fetchをフックして、jsonを返す。

写真

image.png

サンプルコード

self.onfetch = function(event) {
    var requestURL = new URL(event.request.url);
    if (requestURL.pathname.match('/test')) 
    {
        var result = [{ 
            id: 1, 
            name: 'aaaaa', 
            mail: 'aaaaa@gmail.com' 
        }, { 
            id: 2, 
            name: 'bbbbb', 
            mail: 'bbbbb@gmail.com' 
        }, { 
            id: 2, 
            name: 'ccccc', 
            mail: 'ccccc@gmail.com' 
        }, ];
        var response = new Response(JSON.stringify(result), {
            status: 200,
            statusText: 'OK',
            headers: {
                'Content-Type': 'application/json'
            }
        });
        event.respondWith(response);
    }
};



成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?