我创建了一个烧瓶应用程序,它向https://create-react-app-example.vercel.app发出GET请求并缓存react页面。然后从缓存中提供HTML页面。
烧瓶应用程序:
from flask import Flask
import requests_cache
app = Flask(__name__)
session = requests_cache.CachedSession('react_page')
@app.route("/")
def serve_react_page():
return session.get('https://create-react-app-example.vercel.app').text
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)烧瓶应用程序依赖项:
Flask==1.1.2
requests-cache==0.8.1我无法缓存静态文件夹中的内容。
dineshsonachalam@macbook % python3 proxy.py
* Serving Flask app "proxy" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [28/Oct/2021 23:09:40] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [28/Oct/2021 23:09:40] "GET /static/css/main.5f361e03.chunk.css HTTP/1.1" 404 -
127.0.0.1 - - [28/Oct/2021 23:09:40] "GET /static/js/2.087e98bc.chunk.js HTTP/1.1" 404 -
127.0.0.1 - - [28/Oct/2021 23:09:40] "GET /static/js/main.26bec6bc.chunk.js HTTP/1.1" 404 -
127.0.0.1 - - [28/Oct/2021 23:09:40] "GET /static/js/2.087e98bc.chunk.js HTTP/1.1" 404 -
127.0.0.1 - - [28/Oct/2021 23:09:40] "GET /static/js/main.26bec6bc.chunk.js HTTP/1.1" 404 -
127.0.0.1 - - [28/Oct/2021 23:09:40] "GET /manifest.json HTTP/1.1" 404 -

react构建将包含用于存储CSS、js和图像的静态文件夹。
dineshsonachalam@macbook ui % tree build
build
├── asset-manifest.json
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
├── robots.txt
└── static
├── css
│ ├── main.a617e044.chunk.css
│ └── main.a617e044.chunk.css.map
└── js
├── 2.d4015c87.chunk.js
├── 2.d4015c87.chunk.js.LICENSE.txt
├── 2.d4015c87.chunk.js.map
├── 3.b4494d53.chunk.js
├── 3.b4494d53.chunk.js.map
├── main.3dbeb9be.chunk.js
├── main.3dbeb9be.chunk.js.map
├── runtime-main.5d34aaab.js
└── runtime-main.5d34aaab.js.map
3 directories, 18 files是否有任何方法从静态文件夹缓存内容。
发布于 2021-10-29 04:33:31
serve_react_page在这里返回用户在导航到该页面时所看到的内容。其中包括指向/static中文件的链接。
该页面有指向静态资产的链接,当它查找静态资产时,它会询问您的服务器实际处于什么状态--例如https://create-react-app-example.vercel.app/static/css/main.5f361e03.chunk.css。
但是浏览器想要在http://0.0.0.0:5000/static/css/main.5f361e03.chunk.css上找到它,当然这是不存在的。
您可以尝试在您的烧瓶应用程序中设置一个路由,任何请求/static的请求都可以从https://create-react-app-example.vercel.app下载该文件并将其缓存到客户端。
https://stackoverflow.com/questions/69758846
复制相似问题