Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimhttpd hangs with 127.0.0.1 but not localhost in URL #17

Open
hamidb80 opened this issue Jul 4, 2023 · 2 comments
Open

nimhttpd hangs with 127.0.0.1 but not localhost in URL #17

hamidb80 opened this issue Jul 4, 2023 · 2 comments

Comments

@hamidb80
Copy link

hamidb80 commented Jul 4, 2023

Problem

when I use localhost in URL everything works fine,
but when I use http://127.0.0.1:PORT, nimhttpd just does not respond anymore and hangs

Code Example

the provided code copies a image 50 times into the ./temp folder and creates a index.html file for you to see all of them.

import std/[os, sequtils, strutils, math, strformat]
import karax/[karaxdsl, vdom]


func indexPage(root: string, images: seq[string]): VNode =
  buildHtml body:
    for imageName in images:
      img(src = root & imageName, height = "100")
      span: text imageName
      hr()

proc repeatedCopy(filePath, destDir: string, times: int) =
  ## copies file `filePath` into directory `destDir`
  ## for `times` times
  let
    (_, _, ext) = splitFile filePath
    numberLen = toInt ceil log10 tofloat times
  for n in 1..times:
    copyFile filePath, destDir / align($n, numberLen, '0') & ext

proc extractImages(dir: string): seq[string] =
  for path in walkFiles dir/"*":
    let (_, name, ext) = splitFile path
    case ext.toLowerAscii
    of ".png", ".jpg", ".jpeg":
      result.add name & ext

when isMainModule:
  let
    port = parseint paramStr 1
    imagePathToBeCopied = paramStr 2
    localhost = fmt"http://localhost:{port}/"
    ip = fmt"http://127.0.0.1:{port}/"

  discard existsOrCreateDir "./temp"

  repeatedCopy imagePathToBeCopied, "./temp", 50

  writeFile "./temp/index.html":
    # $indexPage(localhost, extractImages "./temp") # <<------------- works fine
    $indexPage(ip, extractImages "./temp") # does not work for some images

run with

nim r play.nim PORT PATH_TO_IMAGE
nimhttpd ./temp -p:PORT

Result

As you can probably see some images does not load at all and reloading the page does not help

image

Additional Info

windows 10 64bit
nim 1.6.12
@hamidb80 hamidb80 changed the title nimhttpd hangs with 127.0.0.1 but not localhost nimhttpd hangs with 127.0.0.1 but not localhost in URL Jul 4, 2023
@treeform
Copy link

I don't know if its related, but I also had nimhttpd just hang. I am not sure why.

@planetis-m
Copy link

planetis-m commented Jul 2, 2024

Hi, I might have the same issue: planetis-m/naylib#122 In the web console this is printed indefinitely:

index.js:759 still waiting on run dependencies:
(anonymous) @ index.js:759
index.js:761 dependency: wasm-instantiate
(anonymous) @ index.js:761
index.js:764 (end of list)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants