elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.64k stars 226 forks source link

404 on any URL #861

Open rchaud opened 1 month ago

rchaud commented 1 month ago

What version of Elysia is running?

1.1.29

What platform is your computer?

Docker

What steps can reproduce the bug?

docker run -it --rm -v "$(pwd):/app" -w /app oven/bun:latest sh
Unable to find image 'oven/bun:latest' locally
latest: Pulling from oven/bun
ba83bbfca944: Already exists
f6f83b953810: Already exists
0804653e8134: Already exists
5b027434e92d: Already exists
cb42e1f96f89: Already exists
Digest: sha256:eb409bed239c3adff079a6b71283f151e802d66b99f643ba7a71e1be7d3da513
Status: Downloaded newer image for oven/bun:latest
# bun create elysia app

$ bun install
bun install v1.1.29 (6d43b366)

+ bun-types@1.1.29
+ elysia@1.1.17

9 packages installed [2.08s]

[2.10s] bun install

[2.83s] bun create elysia

Come hang out in bun's Discord: https://bun.sh/discord

-----

Dependencies were installed automatically.

Created elysia project successfully

# To get started, run:

  cd app
  bun run src/index.ts

# cd app
# bun run src/index.ts
🦊 Elysia is running at localhost:3000

What is the expected behavior?

We are expecting a 200 return code from the URL.

What do you see instead?

% curl localhost:3000/
Hello Elysia%

% curl localhost:3000/ -I
HTTP/1.1 404 Not Found
content-type: text/plain;charset=utf-8
Date: Wed, 02 Oct 2024 16:36:53 GMT
Content-Length: 9

Additional information

It seems any routes I create will result in a 404.

Have you try removing the node_modules and bun.lockb and try again yet?

yes

rchaud commented 1 month ago

Seems I was using the wrong curl argument

rchaud commented 1 month ago

Actually, it seems that curl -I or curl --head is not seeing by Elysia. Im trying to use Uptime Robot and the check is using HEAD.

Kobusvdwalt commented 1 month ago

I am having the same problem. And the downstream effect of this is that provisioning an android device fails because the HEAD call returns 404.

crishoj commented 3 weeks ago

I think this works as intended.

For HEAD requests, you need to explicitly add a .head() handler, or use .all():

import Elysia from 'elysia'

const app = new Elysia()
    .get('/get', () => 'Hello from /get')
    .head('/head', () => 'Hello from /head')
    .all('/all', () => 'Hello from /all')

for (const url of ['https://example.com/get', 'https://example.com/head', 'https://example.com/all']) {
    for (const method of ['GET', 'HEAD']) {
        const res = await app.handle(new Request(url, {method}))
        console.log(method.padEnd(4), url, '→', res.status, await res.text())
    }
}

Output:

image