简体   繁体   中英

How to serve yaml file with sinatra? (not download)

I have a basic Sinatra app, I'd like to serve a yaml file so that it can be read by a gem via http.

I'm just able to download it:

get '/download' do
  send_file './en.yml', :filename => 'en.yml', :type => 'text/yaml'
end

But how can I just serve it without downloading?

Goal is that a gem makes an http request to obtain the content of this endpoint.

Any reason you can't convert the YAML to JSON and serve that?

require 'json'
require 'sinatra'
require 'sinatra/json' # from sinatra-contrib
require 'yaml'

get '/download' do
  json YAML.safe_load(File.read('en.yml'))
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM