简体   繁体   English

使用Sinatra / Rack(在MiddlemanApp中)将PHP文件作为静态文本/ html提供吗?

[英]Use Sinatra/Rack (in MiddlemanApp) to serve PHP files as static text/html?

I'm fairly new to Ruby/Sinatra/Rack. 我是Ruby / Sinatra / Rack的新手。 Been using MiddlemanApp for a couple months. 已经使用MiddlemanApp几个月了。

I have a need for a couple of PHP pages in my middleman static site. 我的中间人静态站点中需要几个PHP页面。 And I'd like to be able to preview those pages in the browser while running middleman server . 我希望能够在运行middleman server在浏览器中预览这些页面。 I don't need the PHP file to be parsed or processed , just served up as is in the preview server and with a Content-type of text/html. 我不需要解析或处理PHP文件 ,只需像在预览服务器中一样使用Content / text / html类型的文件即可。

In an Apache config, it's easy to tell Apache to treat a given file extension as another type of file. 在Apache配置中,很容易告诉Apache将给定的文件扩展名视为另一种文件。 But I don't know where to even start on this in Sinatra/Middleman/Rack. 但是我什至不知道从Sinatra / Middleman / Rack的何处开始。

So: 所以:

Can I set Sinatra or Rack to serve up PHP files as static HTML? 我可以设置Sinatra或Rack来将PHP文件作为静态HTML提供吗? I don't want or expect Sinatra/Rack to parse the PHP. 我既不希望也不希望Sinatra / Rack解析PHP。 I just want the PHP embedded/untouched as static HTML when running middleman server . 我只希望在运行middleman server时将PHP嵌入/保留为静态HTML。

I know that I can run middleman build and use Apache to serve and parse those files, but it's simply tedious to middleman build every 20 seconds. 我知道我可以运行middleman build并使用Apache服务和解析这些文件,但是每20秒middleman build一次middleman build是非常乏味的。

EDIT 编辑

Ok, so I do realize that the above IS the default behavior. 好的,所以我确实意识到以上是默认行为。 I'll amend my question to this: 我将对此问题进行修正:

  • How do I get Sinatra in Middleman App to serve index.php as the index file in the preview server? 如何在Middleman App中获取Sinatra,以将index.php用作预览服务器中的索引文件?

Say I have source/test/index.php.erb and no source/test/index.html.erb . 说我有source/test/index.php.erb ,没有source/test/index.html.erb I'd like middleman server to serve up the /test/index.php on requests for /test/. 我希望middleman server根据/ test /的请求提供/test/index.php。

Not exactly sure what your question is, but do you mean something like this? 不完全确定您的问题是什么,但是您的意思是这样的吗?

get '/test' do 
  erb :'test/index.php'
end

Where you have a file named index.php.erb in your views/test folder 您的views / test文件夹中有一个名为index.php.erb的文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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