【问题标题】:How to use Perfect(Swift) under a VirtualHost(Apach)?如何在虚拟主机(Apache)下使用 Perfect(Swift)?
【发布时间】:2018-07-08 00:43:39
【问题描述】:

我在 Ubuntu 操作系统上安装了 Apache。我的 Ubuntu 使用亚马逊 Lightsail。我设置了一个 VirtualHost 以便像这样使用 Perfect Web 服务器

<Location "/PerfectTemplate">
    ProxyPass http://localhost:8182
    ProxyPassReverse http://localhost:8182
</Location>

我正在尝试从 HTML 进行 POST 操作,但程序引用了 Apache

var try_post_action = """

<form action="./tow" method="post">
//<form action="/tow" method="post">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>

"""

【问题讨论】:

    标签: apache perfect


    【解决方案1】:

    以下Apache conf sn-p

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) - [L,NS,H=perfect-handler]
    

    快速文件

    import PerfectHTTP
    import PerfectHTTPServer
    
    func handler(request: HTTPRequest, response: HTTPResponse) {
        response.setHeader(.contentType, value: "text/html")
        response.appendBody(string: """
    <form action="./PerfectTemplate/test" method="get">
      First name: <input type="text" name="fname"><br>
      Last name: <input type="text" name="lname"><br>
      <input type="submit" value="Submit">
    </form>
    """)
        response.completed()
    }
    
    
    let confData = [
        "servers": [
            [
                "name":"localhost",
                "port":8182,
                "routes":[
                    ["method":"get", "uri":"/", "handler":handler],
                    ["method":"get", "uri":"/test", "handler":handler],
                    ["method":"get", "uri":"/**", "handler":PerfectHTTPServer.HTTPHandler.staticFiles,
                     "documentRoot":"./webroot",
                     "allowResponseFilters":true]
                ],
                "filters":[
                    [
                    "type":"response",
                    "priority":"high",
                    "name":PerfectHTTPServer.HTTPFilter.contentCompression,
                    ]
                ]
            ]
        ]
    ]
    
    do {
        try HTTPServer.launch(configurationData: confData)
    } catch {
        fatalError("\(error)")
    }
    

    【讨论】:

      猜你喜欢
      • 2013-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 2014-05-28
      • 2019-08-25
      • 2012-04-26
      相关资源
      最近更新 更多