Eleventy: `pathPrefix` Configuration Setting broken since 0.7 (--pathprefix Command Line option works)

Created on 15 Jan 2019  Β·  8Comments  Β·  Source: 11ty/eleventy

Just upgraded from 0.6 to 0.7 and can no longer access Browsersync/served site using pathPrefix option, throws Cannot GET error. Reverting to 0.6 restores normal behaviour.

Sample config file:

module.exports = function(eleventyConfig) {
    eleventyConfig.addPassthroughCopy('assets');
    return {
        dir: {
            input: 'src',
            output: 'docs'
        },
        pathPrefix: '/project/',
        dataTemplateEngine: 'njk',
        htmlTemplateEngine: 'njk',
        passthroughFileCopy: true
    };
};

This file results in Cannot GET /project/ error. Chrome console also shows some errors as follows, not sure if relevant:

localhost/:7 Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash [...], or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

and

localhost/:1 Failed to load resource: the server responded with a status of 404 (Not Found)
bug

Most helpful comment

This will be included with 0.7.2

All 8 comments

I tried to compare the DEBUG=socket.io* output, and the difference between 0.6.0 and the newest one is this:

// 0.6.0
"routes":{"/mysubdir/":"./_site"}
// 0.7.1
"routes":{"/mysubdir/":"_site/mysubdir"}

it looks like EleventyServe.js is pointing to the wrong directory, @zachleat

@fewerflatlands , for now maybe you can override that behaviour in your config file, like this :

  eleventyConfig.setBrowserSyncConfig({
    server: {
      baseDir: "_site/_eleventy_redirect",
      routes: { "/mysubdir/": "./_site" }
    }
  });

Thanks @okitavera!

I’ll have a look.

This will be included with 0.7.2

Many thanks!

@zachleat I noticed that even without pathPrefix, the eleventy --serve command does not work for me in 0.7.1 (I get the same CSP errors).

I've just been following the guides so my site only consists of:

.
β”œβ”€β”€ README.md
β”œβ”€β”€ _includes
β”‚   └── layout.njk
β”œβ”€β”€ _site
β”‚   └── README
β”‚       └── index.html
β”œβ”€β”€ package-lock.json
└── package.json

@robdodson can you file another issue? I can’t reproduce but we might be expecting different things from the feature?

Your project structure works as expected for me with:

layout.njk:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title></title>
    </head>
    <body>
        {{ content | safe }}
    </body>
</html>

README.md:

---
layout: layout.njk
---
# Test

dskljfkl

Expected Behavior with already released Eleventy 0.7.1

  • Using npx eleventy --serve --pathprefix=/test/ and navigating to http://localhost:8080/test/README/ works as expected and shows the rendered output
  • Using npx eleventy --serve and navigating to http://localhost:8080/README/ works as expected and shows the rendered output

Just as information until 0.7.2 is released, from https://github.com/11ty/eleventy/issues/384#issuecomment-459895721 it would appear that --pathprefix is working fine but setting the pathprefix in configuration file (.eleventy.js) is what was broken in 0.7.0 and 0.7.1.

my mistake, I was just putting the wrong url in :P

Was this page helpful?
0 / 5 - 0 ratings