Error finding CACerts on the relative path in the CACertPathList option of IDaaSOIDCStrategy in passport-ci-oidc on Cloud Foundry - passport.js

I attempted to create an IDaaSOIDCStrategy. In the options I specify a relative path for the CACerts that begins with "/", in my case "/local/".
const Strategy = new openIdConnect.IDaaSOIDCStrategy(
{
...
addCACert: true,
CACertPathList: [
'/local/<certificate-name>.pem',
'/local/<another-certificate-name>.pem',
}
The path is supposed to be resolved relative to the app root. However, when I deployed the app to Cloud Foundry, it crashed with an error that the first file in the CACertPathList couldn't be found:
ENOENT: no such file or directory
Instead of looking under the app root,the strategy creation code is looking under the root folder of the passport-ci-oidc package, which is where node_modules is installed. In my Cloud Foundry deployment, the root folder of node_modules is not the app's root, it's in a different place, under /home/vcap/deps/0/. The app root is in /home/vcap/app.
What can I do to ensure that the path of the CACerts is resolved properly?

The solution that worked for me is a workaround, but a resolution nonetheless. (The behavior of the strategy code in which it finds the relative path from the root of the passport-ci-oidc package does not match the description in the documentation, which states that it uses the app root, so it may be a defect).
When Cloud Foundry builds dependencies, if there is a node_modules directory under the app root, it will find it, and look for dependencies there, instead of creating a node_modules directory in another location.
In my case, I had originally included node_modules in the .cfignore file, so node_modules was not being pushed to Cloud Foundry. When I removed node_modules from .cfignore, the local node_modules folder, which is under the app root, is pushed directly under the app root. As a result, the root of the passport-ci-oidc package is the same as the app root, so the relative path is expanded from the app root.

Related

Node saving to external folder

I'd like to save all files to an external folder outside of my node application. I'm getting an error, ENOTDIR: not a directory.
backend
├──routes
│ └──savefiles.js
│
externalFolder
How do you write to the external folder?
fs.writeFileSync('../../externalFolder/report.docx', buffer);.
If backend and externalFolder are at the same level and the current working directory is the directory containing savefiles.js, then you need to up one more level with:
fs.writeFileSync('../../../externalFolder/report.docx', buffer);
The first .. gets you to the routes directory. The second one gets you to the backend directory. You need to get to the backend parent with the third .. so you can then reach into the externalFolder directory.
Note, you can debug this yourself with:
console.log(path.resolve('../../externalFolder'));
Also, you can remove a dependence on the current working directory by constructing a path using the module's directory such as:
fs.writeFileSync(path.join(__dirname, '../../../externalFolder/report.docx'), buffer);

Deploy VueJS App in a sub-directory or sub-path

I’m experiencing problems deploying a Vue JS app built using the Webpack CLi to work.
If uploaded in a root directory everything renders fine, but inside a subfolder, all the links break.
I want deploy VueJS App to this url :
https://event.domain.net/webinar
I have added publicPath in vue.config.js :
var path = require(‘path’)
module.exports = {
publicPath: ‘./’
}
But only the css and js folders point to the path /webinar.
For assets, fonts and others still point to the subdomain https://event.domain.net.
CSS and JS point to path /webinar
Asset, fonts still point to subdomain https://event.domain.net/
Console
use value of publicPath as /webinar that should work.
More details are here https://cli.vuejs.org/config/#publicpath
you can configure publicPath even based on environment.
Sagar Rabadiya pointed you to the right link:
create a file called vue.config.js in the project root (where your package.json is located).
prompt the following code snippet inside:
module.exports = {
publicPath: process.env.NODE_ENV === 'production'? '/your-sub-directory/' : '/'
}
and save the file.
Open a terminal and navigate to your project, then run npm run build to generate a production build from it.
As soon as the production build has been generated, copy the contents from it and paste it in the sub-directory you created in the root folder. For example, if you use Apache, the default root directory is the htdocs folder. I've also created a virtual host on the server, maybe you also need to do this.
Open the browser and type the address where your sub-directory lives. For example: http://your-server-url:your-port/your-sub-directory/ Your should see your app now.

How to resolve path to a file within node_modules

Problem loading a file using relative path when my node app is initialised using a another node app
I have created an npm which relies on a file stored relative to project root. something like this
index.js
- res
- config.json
Now I read the config.json using following code
const pathToConfig = path.resolve(__dirname, '../res/config.json')
This works great locally.
But in my prod setup this app is initialised by another node app.
And __dirname resolves to root of that app so all my logic to find config.json get messed up.
Is there any way I can read the file without worrying about how node app was initialised?
Have you tried the command process.cwd()? It is almost the same as __dirname but does differ slightly.

How do I specify the root directory Intern serves for http://localhost:9000?

I have a project called delite where all of its dependencies are at the same level as delite itself, rather than in delite/node_modules.
Previously, running Intern 3, I specified baseUrl: ".." and http://localhost:9000 served one directory above my project, so it could load both delite (http://localhost:9000/delite) and its sister projects (ex: http://localhost:9000/dcl).
Is there a way to do the same thing in Intern 4? Currently, http://localhost:9000 serves the contents of the delite directory only, so I can't load dependencies.
You can use the basePath config option. The path is relative to the location of the test config (intern.json)

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.
When trying to cf push my application I get the following error:
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:
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.
The fail came from my node_modules folder.
Adding .cfignore with node_modules/ fixed the issue.
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.
push now preserves relative symlinks in app files. 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 (e.g. a node_modules folder containing external symlinks).
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 to find all the symlinks under the current directory. 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).
Hope that helps!

Resources