Location of webroot (for css file) in Perfect app












2















I've cloned the PerfectTemplate project and am using it to serve up html as follows…



import PerfectHTTP
import PerfectHTTPServer

var routes = Routes()

routes.add(method: .get, uri: "/test") { request, response in
response.addHeader(.contentType, value: "text/html")
response.setBody(string: """
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test!</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="Welcome">Hello</div>
</body>
</html>
""")
response.completed()
}

routes.add(method: .get,
uri: "/**",
handler: StaticFileHandler(documentRoot: "./webroot", allowResponseFilters: true).handleRequest)

try HTTPServer.launch(name: "localhost",
port: 8181,
routes: routes,
responseFilters: [(PerfectHTTPServer.HTTPFilter.contentCompression(data: [:]), HTTPFilterPriority.high)])


I'm compiling and running with Xcode, and http://localhost:8181/test is returning the html as expected.



The problem is the location of the external css file. As far as I can tell this should be in a folder called webroot, but where should that folder be when running locally?



For reference, I'm coming at this as an iOS dev, so my knowledge of web development and server config is limited.





Update



Per a suggestion on the Perfect Slack group, I added the css file to the project folder (the same folder as Package.swift), and set the Working Directory of the scheme $(PROJECT_DIR) - but I’m getting a 404 trying to load http://localhost:8181/style.css










share|improve this question





























    2















    I've cloned the PerfectTemplate project and am using it to serve up html as follows…



    import PerfectHTTP
    import PerfectHTTPServer

    var routes = Routes()

    routes.add(method: .get, uri: "/test") { request, response in
    response.addHeader(.contentType, value: "text/html")
    response.setBody(string: """
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title>Test!</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
    <div class="Welcome">Hello</div>
    </body>
    </html>
    """)
    response.completed()
    }

    routes.add(method: .get,
    uri: "/**",
    handler: StaticFileHandler(documentRoot: "./webroot", allowResponseFilters: true).handleRequest)

    try HTTPServer.launch(name: "localhost",
    port: 8181,
    routes: routes,
    responseFilters: [(PerfectHTTPServer.HTTPFilter.contentCompression(data: [:]), HTTPFilterPriority.high)])


    I'm compiling and running with Xcode, and http://localhost:8181/test is returning the html as expected.



    The problem is the location of the external css file. As far as I can tell this should be in a folder called webroot, but where should that folder be when running locally?



    For reference, I'm coming at this as an iOS dev, so my knowledge of web development and server config is limited.





    Update



    Per a suggestion on the Perfect Slack group, I added the css file to the project folder (the same folder as Package.swift), and set the Working Directory of the scheme $(PROJECT_DIR) - but I’m getting a 404 trying to load http://localhost:8181/style.css










    share|improve this question



























      2












      2








      2








      I've cloned the PerfectTemplate project and am using it to serve up html as follows…



      import PerfectHTTP
      import PerfectHTTPServer

      var routes = Routes()

      routes.add(method: .get, uri: "/test") { request, response in
      response.addHeader(.contentType, value: "text/html")
      response.setBody(string: """
      <!DOCTYPE html>
      <html lang="en">
      <head>
      <title>Test!</title>
      <link rel="stylesheet" type="text/css" href="style.css">
      </head>
      <body>
      <div class="Welcome">Hello</div>
      </body>
      </html>
      """)
      response.completed()
      }

      routes.add(method: .get,
      uri: "/**",
      handler: StaticFileHandler(documentRoot: "./webroot", allowResponseFilters: true).handleRequest)

      try HTTPServer.launch(name: "localhost",
      port: 8181,
      routes: routes,
      responseFilters: [(PerfectHTTPServer.HTTPFilter.contentCompression(data: [:]), HTTPFilterPriority.high)])


      I'm compiling and running with Xcode, and http://localhost:8181/test is returning the html as expected.



      The problem is the location of the external css file. As far as I can tell this should be in a folder called webroot, but where should that folder be when running locally?



      For reference, I'm coming at this as an iOS dev, so my knowledge of web development and server config is limited.





      Update



      Per a suggestion on the Perfect Slack group, I added the css file to the project folder (the same folder as Package.swift), and set the Working Directory of the scheme $(PROJECT_DIR) - but I’m getting a 404 trying to load http://localhost:8181/style.css










      share|improve this question
















      I've cloned the PerfectTemplate project and am using it to serve up html as follows…



      import PerfectHTTP
      import PerfectHTTPServer

      var routes = Routes()

      routes.add(method: .get, uri: "/test") { request, response in
      response.addHeader(.contentType, value: "text/html")
      response.setBody(string: """
      <!DOCTYPE html>
      <html lang="en">
      <head>
      <title>Test!</title>
      <link rel="stylesheet" type="text/css" href="style.css">
      </head>
      <body>
      <div class="Welcome">Hello</div>
      </body>
      </html>
      """)
      response.completed()
      }

      routes.add(method: .get,
      uri: "/**",
      handler: StaticFileHandler(documentRoot: "./webroot", allowResponseFilters: true).handleRequest)

      try HTTPServer.launch(name: "localhost",
      port: 8181,
      routes: routes,
      responseFilters: [(PerfectHTTPServer.HTTPFilter.contentCompression(data: [:]), HTTPFilterPriority.high)])


      I'm compiling and running with Xcode, and http://localhost:8181/test is returning the html as expected.



      The problem is the location of the external css file. As far as I can tell this should be in a folder called webroot, but where should that folder be when running locally?



      For reference, I'm coming at this as an iOS dev, so my knowledge of web development and server config is limited.





      Update



      Per a suggestion on the Perfect Slack group, I added the css file to the project folder (the same folder as Package.swift), and set the Working Directory of the scheme $(PROJECT_DIR) - but I’m getting a 404 trying to load http://localhost:8181/style.css







      html css swift xcode perfect






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 14:18







      Ashley Mills

















      asked Nov 15 '18 at 21:43









      Ashley MillsAshley Mills

      28.9k989117




      28.9k989117
























          1 Answer
          1






          active

          oldest

          votes


















          0














          With help from the Perfect Slack group, I found a solution. The missing piece for me was the webroot folder. I'd assumed this was some kind of alias, but it turns out that you do need to create an actual folder called webroot. So…




          1. Set the Working Directory of the scheme to $(PROJECT_DIR)

          2. In the project folder, create a folder named webroot and add the css file to that folder. It should look like this…


          enter image description here



          I'm sure all the seasoned web devs are laughing at me right now!






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328315%2flocation-of-webroot-for-css-file-in-perfect-app%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            With help from the Perfect Slack group, I found a solution. The missing piece for me was the webroot folder. I'd assumed this was some kind of alias, but it turns out that you do need to create an actual folder called webroot. So…




            1. Set the Working Directory of the scheme to $(PROJECT_DIR)

            2. In the project folder, create a folder named webroot and add the css file to that folder. It should look like this…


            enter image description here



            I'm sure all the seasoned web devs are laughing at me right now!






            share|improve this answer




























              0














              With help from the Perfect Slack group, I found a solution. The missing piece for me was the webroot folder. I'd assumed this was some kind of alias, but it turns out that you do need to create an actual folder called webroot. So…




              1. Set the Working Directory of the scheme to $(PROJECT_DIR)

              2. In the project folder, create a folder named webroot and add the css file to that folder. It should look like this…


              enter image description here



              I'm sure all the seasoned web devs are laughing at me right now!






              share|improve this answer


























                0












                0








                0







                With help from the Perfect Slack group, I found a solution. The missing piece for me was the webroot folder. I'd assumed this was some kind of alias, but it turns out that you do need to create an actual folder called webroot. So…




                1. Set the Working Directory of the scheme to $(PROJECT_DIR)

                2. In the project folder, create a folder named webroot and add the css file to that folder. It should look like this…


                enter image description here



                I'm sure all the seasoned web devs are laughing at me right now!






                share|improve this answer













                With help from the Perfect Slack group, I found a solution. The missing piece for me was the webroot folder. I'd assumed this was some kind of alias, but it turns out that you do need to create an actual folder called webroot. So…




                1. Set the Working Directory of the scheme to $(PROJECT_DIR)

                2. In the project folder, create a folder named webroot and add the css file to that folder. It should look like this…


                enter image description here



                I'm sure all the seasoned web devs are laughing at me right now!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 17 '18 at 14:33









                Ashley MillsAshley Mills

                28.9k989117




                28.9k989117
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328315%2flocation-of-webroot-for-css-file-in-perfect-app%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    List item for chat from Array inside array React Native

                    Thiostrepton

                    Caerphilly