[{"data":1,"prerenderedAt":148},["ShallowReactive",2],{"/2026/02/03-http-server-vs-serve-run-from-dist-directory":3},{"id":4,"title":5,"body":6,"date":139,"description":50,"extension":140,"meta":141,"navigation":142,"path":143,"robots":144,"seo":145,"stem":146,"__hash__":147},"posts/2026/02/03 http-server-vs-serve-run-from-dist-directory.md","03 Http Server Vs Serve Run From Dist Directory",{"type":7,"value":8,"toc":136},"minimark",[9,18,38,51,54,62,70,72,84,92,94,106,114,116,123,131,133],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"http-server-vs-serve-run-from-dist-directory","Http-server vs Serve: Run from dist directory",[19,20,21,22,30,31,37],"p",{},"My team had to test an MFE repository locally. However, it's meant to be run from \"dist\" folder after build and package steps. I saw some recommendation online to use ",[23,24,29],"code",{"className":25},[26,27,28],"bg-gray-200","p-2","rounded","http-server"," (",[32,33,34],"a",{"href":34,"rel":35},"https://www.npmjs.com/package/http-server",[36],"nofollow","). So, I gave it a try and I managed to get it running really quick. And I quickly found issues too. After installation, I just need to run:",[39,40,41],"code-block",{},[42,43,48],"pre",{"className":44,"code":46,"language":47},[45],"language-text","http-server dist\n","text",[23,49,46],{"__ignoreMap":50},"",[52,53],"br",{},[19,55,56,57,61],{},"Accessing from the client, browser threw CORS error. Fixing that was quick with ",[23,58,60],{"className":59},[26,27,28],"--cors"," option.",[39,63,64],{},[42,65,68],{"className":66,"code":67,"language":47},[45],"http-server --cors dist\n",[23,69,67],{"__ignoreMap":50},[52,71],{},[19,73,74,75,78,79,83],{},"Then, for somewhat reason, it didn't send Content-Type response header, so the client got it wrong when parsing the js file. I had to add ",[23,76,77],{},"-e js"," to set the default Content-Type to ",[23,80,82],{"className":81},[26,27,28],"application/javascript",".",[39,85,86],{},[42,87,90],{"className":88,"code":89,"language":47},[45],"http-server -e js --cors dist\n",[23,91,89],{"__ignoreMap":50},[52,93],{},[19,95,96,97,30,101,105],{},"It's not too bad, but I'm looking for a little simpler solution and I had good experience with ",[23,98,100],{"className":99},[26,27,28],"serve",[32,102,103],{"href":103,"rel":104},"https://www.npmjs.com/package/serve",[36],"). With serve, after installation, I just need to run:",[39,107,108],{},[42,109,112],{"className":110,"code":111,"language":47},[45],"serve dist\n",[23,113,111],{"__ignoreMap":50},[52,115],{},[19,117,118,119,122],{},"Same case with http-server, I need to enable CORS by adding ",[23,120,60],{"className":121},[26,27,28]," option, so it becomes:",[39,124,125],{},[42,126,129],{"className":127,"code":128,"language":47},[45],"serve --cors dist\n",[23,130,128],{"__ignoreMap":50},[52,132],{},[19,134,135],{},"However, it automatically sends the right Content-Type response header.",{"title":50,"searchDepth":137,"depth":137,"links":138},2,[],"2026-02-03T00:00:00.000Z","md",{},true,"/2026/02/03-http-server-vs-serve-run-from-dist-directory",null,{"title":5,"description":50},"2026/02/03 http-server-vs-serve-run-from-dist-directory","O4S9kO1Q7-5AEmoDj6EVgWWCFmKaBFugCzHZ0Hj9VA0",1785167451580]