GithubHelp home page GithubHelp logo

Comments (8)

grkek avatar grkek commented on June 2, 2024

Could you explain the issue with more details?

from grip.

18183883296 avatar 18183883296 commented on June 2, 2024

Now to set routing for static files

class DemoController < Grip::Controllers::Http
  def getHtml(context : Context) : Context
    context
      .send_file("./public/index.html")
  end
end

class Application < Grip::Application
  def initialize(@port : Int32)
    super(environment: "development", serve_static: true)

    scope "/" do
      get "/html", DemoController, as: :getHtml # This works well.

      scope "/foo" do
      get "/html", DemoController, as: :getHtml
      # Request to host/foo/html => ok
      # Request to other static files => 404 Not Found
      # In the url http://localhost/foo/static/js/main.2ee217bf.js, /foo is not expected.
      end
    end
  end
  ...
end

I prefer the way in gofiber
QQ截图20230524221021

from grip.

grkek avatar grkek commented on June 2, 2024

is this what you are looking for?

from grip.

18183883296 avatar 18183883296 commented on June 2, 2024

is this what you are looking for?

I have set the static file directory and assigned serve_static true.
It can only handle request to root path, right?

from grip.

18183883296 avatar 18183883296 commented on June 2, 2024

I mean the url path.

from grip.

grkek avatar grkek commented on June 2, 2024

is this what you are looking for?

I have set the static file directory and assigned serve_static true. It can only handle request to root path, right?

Depends on how you structure your directories, for example:

public/
  images/
    cat.jpeg
  pages/
    cat.html

  index.html

You will be able to access cat.jpeg by /images/cat.jpeg and cat.html by /pages/cat.html.

from grip.

18183883296 avatar 18183883296 commented on June 2, 2024

I mean the prefix part of the path unrelated to the file structure.
I'm seeking for a portable solution.

For example, to access the same files

app.Static("/foo", "./public") => GET http://localhost/foo/index.html
app.Static("/foo/bar", "./public") => GET http://localhost/foo/bar/index.html
app.Static("/foo/bar/baz", "./public") => GET http://localhost/foo/bar/baz/index.html

from grip.

grkek avatar grkek commented on June 2, 2024

I mean the prefix part of the path unrelated to the file structure. I'm seeking for a portable solution.

For example, to access the same files

app.Static("/foo", "./public") => GET http://localhost/foo/index.html
app.Static("/foo/bar", "./public") => GET http://localhost/foo/bar/index.html
app.Static("/foo/bar/baz", "./public") => GET http://localhost/foo/bar/baz/index.html

It could be an interesting feature, I will leave this open.

from grip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.