Next.js: Static resources are being rendered from the wrong place (on custom server)

Created on 27 Dec 2016  路  3Comments  路  Source: vercel/next.js

I'm getting weird (and in my opinion wrong) behavior with static resources when I use custom server (on 2.0.0 Beta).
For example, if my custom server directs a request to "/blog/:id", then the static resources are being looked up in "./blog/static/image.jpg".

For easy reproduction, I've edited the render method of "blog" in "parameterized-routing":

return <div>
      <h1>My {this.props.id} blog post</h1>
      <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
        tempor incididunt ut labore et dolore magna aliqua.
      </p>
      <img src="./static/x.jpg" />
    </div>

And ofcourse added an image named "x.jpg" to "static" folder.

I can work it around by looking the file in "../static/x.jpg", but this is wrong since it exploits the fact that blog does not sit under index.js.

Most helpful comment

Shouldn't it be <img src="/static/x.jpg" /> (no ./) ?
I assumed the page is served on /blog/id.

All 3 comments

@DvirSh could you send us a sample repo.
So, we could have a look at this closer.

Shouldn't it be <img src="/static/x.jpg" /> (no ./) ?
I assumed the page is served on /blog/id.

@nkzawa your'e right!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jesselee34 picture jesselee34  路  3Comments

lixiaoyan picture lixiaoyan  路  3Comments

knipferrc picture knipferrc  路  3Comments

ghost picture ghost  路  3Comments

flybayer picture flybayer  路  3Comments