1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

任意のHTTP ステータスコードを返すWebサーバーを雑に構築する

1
Posted at

はじめに

テスト目的で任意のHTTPステータスコードを返すWebサーバーが必要になり、実際に作ってみたので備忘録としてアプトプットします。

方法

VM起動時にブートストラップのスクリプトとして以下を動作させます。

init.sh
#! /bin/bash
apt update 
apt install -y python3 python3-pip 
pip3 install flask

cat << EOF > ./app.py
from flask import Flask
import random

app = Flask(__name__)

@app.route('/')
def run():
    # この部分に任意のステータスコードを入れる
  status_code = [100, 200, 300, 400, 500]
  return '', random.choice(status_code)

if __name__ == '__main__':
  app.run(host='0.0.0.0', port=80)
EOF

sudo nohup python3 app.py &

Azure VMでブートストラップさせる方法については以下の記事に書いているので、ご参照ください。

おわりに

用途は限られていますが、お役に立てれば幸いです。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?