Сниппет библиотеки на Python3.
import os
from http.server import HTTPServer, SimpleHTTPRequestHandler
PORT = 22870
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET')
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
return super(CORSRequestHandler, self).end_headers()
def do_GET(self):
if not os.path.exists(self.translate_path(self.path)):
self.path = 'index.html'
return SimpleHTTPRequestHandler.do_GET(self)
# Задаем директорию, в которой находится ваш SPA
os.chdir('archive/dist/pwa')
httpd = HTTPServer(('localhost', PORT), CORSRequestHandler)
print("Serving at port", PORT)
httpd.serve_forever()