Getting Meteor private folder path in Meteor Deploy Environment

旧巷老猫 提交于 2020-01-02 09:41:08

问题


I need to get the path of the file inside the private folder. On my local machine I was able to get it by using the path "../../../../../", however, when I deployed to meteor server using meteor deploy, it doesn't work anymore. Also I tried to log the current directory using process.cwd() and got the following, which is different from the structure I got on my local machine:

/meteor/containers/3906c248-566e-61b7-4637-6fb724a33c16/bundle/programs/server

The directory logged from my local machine gives:

/Users/machineName/Documents/projectName/.meteor/local/build/programs/server

Note: I am using this path to setup https://www.npmjs.com/package/apn


回答1:


You can use assets/app/ as the relative path. While this may not make sense on the first look Meteor re-arranges your /private directory to map to assets/app from the /programs/server directory. This is both in development and production.

Basically assume that private/ maps to assets/app/.




回答2:


Call Assets.absoluteFilePath(assetPath) on one of the assets in the private folder, then chop of the name of the asset file from the string you get back, e.g., assuming you have a file called test.txt in the private folder:

var aFile = 'test.txt';// test.txt is in private folder
var aFilePath = Assets.absoluteFilePath(aFile);
var aFolder =  aFilePath.substr(0, aFilePath.length - aFile.length);
console.log(aFolder);

https://docs.meteor.com/api/assets.html#Assets-absoluteFilePath



来源:https://stackoverflow.com/questions/29743806/getting-meteor-private-folder-path-in-meteor-deploy-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!