title: How to serve Flask With Http Server
body: <p>I would like to develop an app that uses both Flask and httpd.
  Flask publishes HTML-related files, and httpd publishes files in local files.</p>
  
  <p>It is for browsing local files published in httpd from Flask HTML.</p>
  
  <p>Though the port numbers of Flask and httpd are different, it seems that httpd server side is not working.
  Connection refused error occurs when connecting to httpd server.</p>
  
  <hr>
  
  <p><strong>Added the intention of the question.</strong></p>
  
  <p>I want to run Flask's built-in web server and HTTPServer simultaneously from a script.
  I just want to be able to see myself, not to expose it to the network.</p>
  
  <p>I'm looking for a mechanism that can be completed with the app.py script without using WSGI.</p>
  
  <hr>
  
  <p><strong>Added additional information to the question.</strong></p>
  
  <p>This question uses Flask and Python's HTTPServer, but using NodeJS's HTTPServer instead of HTTPServer seems to work well.
  (Comment out <code>run()</code>)</p>
  
  <p>I would like to complete in Python if possible without using NodeJS HTTPServer.</p>
  
  <p><a href="https://www.npmjs.com/package/http-server" rel="nofollow noreferrer">https://www.npmjs.com/package/http-server</a></p>
  
  <pre><code>C:\Users\User\Videos&gt;http-server
  Starting up http-server, serving ./
  Available on:
    http://127.0.0.1:8080
  Hit CTRL-C to stop the server
  ...
  </code></pre>
  
  <hr>
  
  <p>version</p>
  
  <pre><code>Flask==1.0.2
  Python 3.7
  </code></pre>
  
  <p>Can I not start each server with the following code?</p>
  
  <p>templates/index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;video src="http://localhost:8080/video.mp4"&gt;&lt;/video&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>python(app.py)</p>
  
  <pre><code>from http.server import SimpleHTTPRequestHandler, HTTPServer
  
  from flask import Flask, render_template
  
  app = Flask(__name__)
  
  
  @app.route('/')
  def hello_world():
      return render_template('index.html')
  
  
  class Handler(SimpleHTTPRequestHandler):
      def __init__(self, *args, directory=None, **kwargs):
          super().__init__(*args,
                           directory=r'C:\Users\User\Videos',
                           **kwargs)
  
  
  def run(server_class=HTTPServer, handler_class=Handler):
      server_address = ('localhost', 8000)
      httpd = server_class(server_address, handler_class)
      httpd.serve_forever()
  
  
  if __name__ == '__main__':
      app.run(host='localhost', port=5000)
      run()
  </code></pre>
  
  <p>It may not have been transmitted well. I'm sorry.<br>
  Thank you very much.</p>