简体   繁体   中英

Invalid serving of static file with aiohttp

I have simple aiohttp one-page web app and want to serve static files with aiohttp itself

app.router.add_static('/static/', os.path.join(root_path, 'static'))

But when accessing resource from browser I have an error Uncaught SyntaxError: Invalid or unexpected token because index.js file was served in some unexpected way. 在此处输入图片说明 在此处输入图片说明

Env: aiohttp==1.0.3 , Python 3.5.2 , Ubuntu 16.04.1 LTS

浏览器响应的一些标题

Was the file saved improperly or it's OS error or something wrong with aiohttp itself?

So the reason of the error was os sendfile that was caching/serving files in some wrong way. export AIOHTTP_NOSENDFILE=1 solved an issue. Link with more details here . Of course, for production environment use nginx to serve your static files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM