Nuxt generated project has wrong axios call
Opened this issue · 4 comments
Hi guys,
I am using nuxtent to generate static site, here is my issue:
with such nuxtent config:
content: [
[
'project/node/',
{
page: 'project/node/_slug',
permalink: 'project/node/:slug',
isPost: false,
generate: ['get', 'getAll']
}
]
]
and content folder:
content
|- project
| |- node
| | |- post1.md
| | |- post2.md
nuxt generate
will create something like
dist
|- _nuxt
| |- content
| | |- project
| | | |- node
| | | | |- project.node
| | | | | |- post1.json
| | | | | |- post2.json
however, after I host the dist folder and want to check post1, axios will ask resource from https://domainname/_nuxt/content/project/node/project.node.post1.json
and cause an error since the right path should be
https://domainname/_nuxt/content/project/node/project.node/post1.json
.
I can make thing work by adding a line in
to replace the last dot to slash:
const allButFirstSlash = /(?!^\/)(\/)/g
const lastDot = /\.(?=[^.]*$)/
const serializedPermalink = permalink.replace(allButFirstSlash, '.').replace(lastDot,'/');
I think another solution is to rearrange how nuxtent generate nuxt routes in
nuxtent-module/lib/content/build.js
Line 122 in 8f7afaa
to make nuxt generate based on page path and content name
Is a folder named project.node
? If so then yea it uses regex to match routes so we'd need to improve the command but this is a pretty unusual case, not sure if it is even recommended to use periods in file names
Yeah. I don't think it is an unusual case. It seems like if the permalink contains path
in order to inject right path to the nuxt->generate->router config
nuxtent-module/lib/content/build.js
Lines 121 to 124 in 8f7afaa
then the generated nuxtent content folder in dist will contain periods in file names.
I dislike those periods either but I have no choice. As I said, maybe it's better to leave permalink out of path info, and inject both path and permalink in the code above
Anyway, thank you so much to create this tool, the normal SSR function works pretty well. But I have to use nuxt and nuxtent to generate static site, so...
I'm sorry I'm not fully understanding - is an error only occurring when you generate the content? If so then yes it deals with the build file.
The problem likely lies here:
nuxtent-module/lib/content/build.js
Lines 5 to 12 in 8f7afaa
Feel free to do a PR and if you have questions you can ask them in the slack channel
cool, I will give it a try