2020-01-27 :-|
_ 労
ストレージ労。粛々と
_ [npm][testing][JSON][mock]JSON のための mock サーバー
typicode/json-server: Get a full fake REST API with zero coding in less than 30 seconds (seriously)
JSON を返すためだけのものです。他のコンテンツは返せないもよう。
環境
Arch Linux
準備
npm をインストールする
% sudo pacman -S npm
npm install したら怒られた
% sudo npm install json-server node: error while loading shared libraries: libicui18n.so.64: cannot open shared object file: No such file or directory
help だけでもダメ
% npm --help node: error while loading shared libraries: libicui18n.so.64: cannot open shared object file: No such file or directory
これか? https://www.archlinux.org/packages/core/x86_64/icu/files/
インストール済みだった。じゃあ違うな。
% pacman -Ss icu        
core/icu 65.1-2 [インストール済み]
    International Components for Unicode library
nodejs を入れ直してみる。衝突してるとか言ってますね。これが原因か?
% sudo pacman -S nodejs
依存関係を解決しています...
衝突するパッケージがないか確認しています...
:: nodejs と nodejs-lts-carbon が衝突しています。nodejs-lts-carbon を削除しますか? [y/N] y
パッケージ (2) nodejs-lts-carbon-8.16.0-1 [削除]  nodejs-13.7.0-1
合計ダウンロード容量:   7.29 MiB
合計インストール容量:  26.54 MiB
最終的なアップグレード容量:   7.91 MiB
:: インストールを行いますか? [Y/n] 
:: パッケージを取得します...
 nodejs-13.7.0-1-x86_64                                 7.3 MiB  25.2 MiB/s 00:00 [----------------------------------------------] 100%
(1/1) キーリングのキーを確認                                                      [----------------------------------------------] 100%
(1/1) パッケージの整合性をチェック                                                [----------------------------------------------] 100%
(1/1) パッケージファイルのロード                                                  [----------------------------------------------] 100%
(1/1) ファイルの衝突をチェック                                                    [----------------------------------------------] 100%
(2/2) 空き容量を確認                                                              [----------------------------------------------] 100%
:: パッケージの変更を処理しています...
(1/1) 削除 nodejs-lts-carbon                                                      [----------------------------------------------] 100%
(1/1) インストール nodejs                                                         [----------------------------------------------] 100%
nodejs の提案パッケージ
    npm: nodejs package manager [インストール済み]
:: トランザクション後のフックを実行...
(1/1) Arming ConditionNeedsUpdate...
再度実行。 OK らしい
% npm --help           
Usage: npm <command>
where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami
npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview
Specify configs in the ini-formatted file:
    /home/miwa/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm@6.13.6 /usr/lib/node_modules/npm
インストールできた
% sudo npm install -g json-server /usr/bin/json-server -> /usr/lib/node_modules/json-server/lib/cli/bin.js + json-server@0.15.1 added 237 packages from 128 contributors in 6.235s
試す
db.json を用意する
{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}
起動する。 hi!
% json-server --watch db.json
  \{^_^}/ hi!
  Loading db.json
  Done
  Resources
  http://localhost:3000/posts
  http://localhost:3000/comments
  http://localhost:3000/profile
  Home
  http://localhost:3000
  Type s + enter at any time to create a snapshot of the database
  Watching...
とりあえずアクセスしてみる
コンソールにはこんなのが出る
GET /posts/1 200 6.463 ms - 63
ウェブブラウザにはこんなのが出る。ok
{
  "id": 1,
  "title": "json-server",
  "author": "typicode"
}
静的ファイル Static file server
JSON or HTML or CSS は返せるとのこと。
mkdir public echo 'hello world' > public/index.html json-server db.json
ローカルにアクセス
ウェブブラウザにはこんな
hello world
_ [python][http][ウェブサーバー][testing]python の簡易ウェブサーバー
環境
- Arch Linux
 - python3
 
試す1
サーバー起動
% python -m http.server
アクセスする。はい
% curl http://localhost:8000/ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Directory listing for /</title> </head> <body> <h1>Directory listing for /</h1> <hr> <ul> <li><a href="db.json">db.json</a></li> <li><a href="hoge.txt">hoge.txt</a></li> <li><a href="public/">public/</a></li> </ul> <hr> </body> </html>
試す2
テキトーなコンテンツを返却してみる。
% mkdir public % echo 'hogehoge' > public/hoge.txt % python -m http.server
取得。はい
% curl http://localhost:8000/public/hoge.txt hogehoge
[ツッコミを入れる]



