简体   繁体   English

NodeJS / CloudFoundry-失败:应用程序上传无效:Symlink指向根文件夹之外

[英]NodeJS/CloudFoundry - failed: The app upload is invalid: Symlink(s) point outside of root folder

I'm testing CloudFoundry on IBM and are running NodeJS. 我正在IBM上测试CloudFoundry,并且正在运行NodeJS。

When trying to cf push my application I get the following error: 尝试cf push我的应用程序时,出现以下错误:

failed: The app upload is invalid: Symlink(s) point outside of root folder

In my appllcation I have the following code: 在我看来,我有以下代码:

return res.sendFile(path.join(__dirname +'/tvshows/'+ guide +'.html'));

When not using path.join and simply use: 不使用path.join时,只需使用:

return res.sendFile(path.join('./tvshows/'+ guide +'.html'));

I get this error instead: 我得到这个错误:

TypeError: path must be absolute or specify root to res.sendFile

What to do? 该怎么办?

I've also tried stuff like path.join((process.env.BUILD_DIR || __dirname), and return res.sendFile('index.html', { root: path.join(__dirname, 'tvshows', guide) }); but no luck. 我也尝试过类似path.join((process.env.BUILD_DIR || __dirname),类的东西path.join((process.env.BUILD_DIR || __dirname),return res.sendFile('index.html', { root: path.join(__dirname, 'tvshows', guide) });但没有运气。

The fail came from my node_modules folder. 失败来自于我的node_modules文件夹。 Adding .cfignore with node_modules/ fixed the issue. .cfignore node_modules/添加.cfignore可以解决此问题。

You didn't mention the version of the cf cli that you're using, but I think that this is expected behavior starting with version 6.34.0. 您没有提到正在使用的cf cli的版本,但是我认为这是从6.34.0版本开始的预期行为。

push now preserves relative symlinks in app files. 现在,push在应用程序文件中保留了相对的符号链接。 This makes it easier to work with Node.js apps using npm link, but note that it now errors when it detects a symlink pointing outside the app folder (eg a node_modules folder containing external symlinks). 这使使用npm链接使用Node.js应用程序更加容易,但是请注意,当它检测到指向应用程序文件夹外部的符号链接(例如,包含外部符号链接的node_modules文件夹)时,它现在会出错。

https://github.com/cloudfoundry/cli/releases/tag/v6.34.0 https://github.com/cloudfoundry/cli/releases/tag/v6.34.0

I think you're running into the second part, "how errors when it detects a symlink pointing outside the app folder". 我认为您正在进入第二部分,“当它检测到指向应用程序文件夹外部的符号链接时如何出错”。 It's nothing to do with the code in your app, but rather somewhere in your project folder there is a symlink which references another file that is not under the root of your project. 这与应用程序中的代码无关,而是在项目文件夹中的某个地方有一个符号链接,该符号链接引用了另一个不在项目根目录下的文件。

If you're on a unix-like system you can run find . -type l 如果您使用的是类似Unix的系统,则可以运行find . -type l find . -type l to find all the symlinks under the current directory. find . -type l查找当前目录下的所有符号链接。 Then you just need to figure out which one is pointing outside of the project root. 然后,您只需要找出哪个指向项目根目录之外即可。

Options are to remove that symlink, point it to something under your project root or use .cfignore to ignore that file (which is what you ended up doing). 选项是删除该符号链接,将其指向项目根目录下的某个位置,或使用.cfignore忽略该文件(最终您将执行此操作)。

Hope that helps! 希望有帮助!

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

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