TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Building an "Easy" Web Application

78 点作者 luu3 个月前

16 条评论

esprehn3 个月前
You can impose a timeout on a fetch with a one liner:<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;AbortSignal&#x2F;timeout_static" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;AbortSignal...</a><p>Part of the awkwardness in the post is also mixing what looks like express with promises. I think using an async function as the handler with express 5 would probably feel a lot nicer.<p>I agree about CORS being frustrating. I think we should have allowed totally anonymous fetch requests across domains for saved to home screen PWAs (or with a permission prompt.) Missing that feature means you end up needing native apps for a lot of things that otherwise are totally reasonable web apps. CORS does make sense though because the alternative is drive by attacks against your local network from random web pages. And since the S in IOT stands for security that seemed like a bad idea at the time.
评论 #42997061 未加载
评论 #43006057 未加载
araes3 个月前
I sympathize with the authors pain, and at least from the comments, it sounds like most have a similar view of CORS. Many weeks of face -&gt; keyboard in response.<p>At some point trying to write JS, I really started believe that the people who implemented CORS did it just to break every single part of the world wide web that might ever be enjoyable.<p>It really felt like somebody held out a beautiful idea with AJAX, and requests lacking synchronization, and then the only response was endless exploits, security holes, patches that took away functionality, and posts like the authors. &quot;This idea seems so simple...nevermind, &#x27;Access-Control-Allow-Origin&#x27; ERROR&quot;
blopker3 个月前
There is another solution, in this specific case. If all they wanted is to start returning the test results before all the tests are done, a streaming http response can be used.<p>In Bottle, returning a generator or iterator will send the response in chucks, instead of all at once. The effect would be that the test results load in one by one, providing the user with feedback. No JavaScript needed.
codelikeawolf3 个月前
&gt; It was also getting harder and harder to debug as JavaScript has no timeout functionality I would have had to wrap that request in another promise.<p>I&#x27;m pretty sure you could use an AbortController to address this? But it&#x27;s one of those things you have to know about. I <i>completely</i> understand the author&#x27;s frustration with CORS, but I don&#x27;t think JS is to blame here. I have felt a similar level of frustration whenever I try to use a language other than JS to work with JSON. Does that mean the language sucks? I would say no. I don&#x27;t think this made a compelling case for avoiding JS, but I would never want to deny someone the catharsis from venting about technology.
xnx3 个月前
(2020)<p>&gt; Three days wasted. I should have just written the PHP script .<p>The good news is that any leading class LLM today would certainly be able to one-shot translation of the script from Python to PHP or create it in PHP.
评论 #43001432 未加载
Evidlo3 个月前
CORS has killed a lot of my SPA ideas too. Also I&#x27;ve been toying with Svelte which I was told was a lightweight framework. But you still need npm to use it which generates dozens of other boilerplate files.<p>The JS ecosystem does indeed suck.
评论 #43001423 未加载
评论 #42997866 未加载
gbro3n3 个月前
The JS Frameworks always feel fun to start with, but then I always end up realising how complex and flakey the tool chain is and switch to something simpler.<p>ASP.NET + alpine.js is my current happy place. If I need a JS lib then I get it from unpkg.com and avoid npm.<p>Then Docker on a Digital Ocean Container App is a really easy way to CI&#x2F;CD.
评论 #42999664 未加载
unavoidable3 个月前
&gt; I feel like every time I look at JavaScript it’s different .<p>So much truth in this. It&#x27;s amazing that JS has managed to survive (even thrive!) in spite of the constant fundamental backwards-breaking changes every few cycles. Maybe that speaks to the lack of web based alternatives than anything else.
评论 #43001645 未加载
totallykvothe3 个月前
I wonder what the environmental impact of CORS is, given that it is the sole reason to spin up a node proxy server every time it kills someone&#x27;s dreams.
theanonymousone3 个月前
Trying to traverse the web landscape and&#x2F;or getting out of one&#x27;s comfort zone is of course a very valid incentive. But if one wants to &quot;transforms a small Python utility&quot; by &quot;turning it into a web application&quot;, I believe more efficient paths could be tried.<p>Streamlit is not mentioned in the article, yet I can argue that is unbeatable and that by a large margin in how quick it is to get from a Python script to a decent, functioning web application.<p>In general, going one-language, full-stack (Vaadin, Streamlit etc..) is probably the right path for anyone who doesn&#x27;t want do front-end but has to. IMHO of course.
beretguy3 个月前
&gt; Three days wasted. I should have just written the PHP script.<p>PHP is the right tool for the job of making websites.
adltereturn3 个月前
I agree with your point of view; CORS will at least torment you for a while until you finally resolve it. With the help of GPT, I have at least tried 1. Vite proxy, 2. Java Spring WebMvcConfigurer CORS config, and 3. Nginx proxy... This is really exhausting.
kennywinker3 个月前
Ah yes, another “this hammer is a terrible paintbrush!” blog post. Bonus points for the dig at node_modules bloat.<p>You can write a post like this about the frustrations of any language &#x2F; tool &#x2F; framework - just go in with random expectations and limited understanding - and when you encounter an obstacle don’t attempt to learn why it’s there.
评论 #43001881 未加载
rk063 个月前
Is there a way one can make a JS fetch() call and instruct browser to not send cookies etc, so CORS limitation won&#x27;t be applied?<p>CORS is basically happening because of the sensitive data that browser sends by default, so if browser is not sending such info, then CORS also need not be applied
评论 #43000810 未加载
评论 #43000167 未加载
theincredulousk3 个月前
not a web person - why does the original approach not have the CORS problem? Isn&#x27;t it still generating the request from the same local machine?
评论 #42997499 未加载
评论 #42997444 未加载
robertlagrant3 个月前
If you want a little more interactivity you could use SSE[0] to push results as they come back.<p>[0] <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;Server-sent_events&#x2F;Using_server-sent_events" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;API&#x2F;Server-sent...</a> - I don&#x27;t think Bottle supports this though; you might have to move to a different WSGI server.
评论 #43002220 未加载