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

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)

Related

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.

NodeJS - Paths break after deployment

I deploy my NodeJS Projects with supervisord. Strangely most of the paths, which are paths
inside the served index.html: links to static files (stylesheets and js files)
inside javascript files, require statements to other files(e.g.: require('./scripts/'))
I believe the reason for that to be the command node "path/to/my/application/app" since it runs the application from a different directory.
How can i avoid changing the paths whenever i push a new version of my application to production?
Can you recommend any tools to solve this problem? Is there a clean way of setting the paths so that the application works so i can run it from anywhere(my local machine/my webspace)?
Use a relative path. For example if index.html is in a directory as same as a .js file referring it u can use ('./index.html'). If it were in a parent directory u could use (../index.html)

Why does require() not require an absolute path but an express.static() does?

I am trying to run my index.js script from outside the project directory. My project structure is as follows:
app
- config
- config.js
- public
- index.html
- src
- index.js
Now when I run my src/index.js from outside my app folder, require() is able to resolve the relative paths
const config = require(`../config/config`);
On the other hand express.static is not able to resolve such relative paths.
e.g. app.use(express.static("../public"));
Why do I need to use path.join and get the absolute path?
require() works off __dirname which is independent of what the current directory was when your app was loaded. It's always the directory where the module is located in, so it is consistent.
express.static() when used with relative paths uses the directory that the main app was launched form, so if you use relative paths, its behavior varies depending upon how you launch the app.
From the express doc for serving static files:
However, the path that you provide to the express.static function is
relative to the directory from where you launch your node process. If
you run the express app from another directory, it’s safer to use the
absolute path of the directory that you want to serve
So, if you want the directory to be module relative, you have to manually combine your path with __dirname to make a full path, as you have discovered.

How do I serve static files for my node-js server which are in my application root directory

Using app.use(express.static('public')) serves the files located under public folder
But if my files are outside the public folder in my application root directly how to serve them.
If you want to serve files in a folder outside of the current working directory, './../<dir_name>' is the way to go.
If you want to serve individual files instead of a directory, then you can use either,
app.use("/<some_url>", express.static(__dirname + '<path_to_file>'));
or
res.sendFile('<path_to_file>');
or use a simple library like, https://www.npmjs.com/package/connect-static-file.
I recommend the first approach though.
Note: replace the <text> with your file names and path names as required.
You can use ./../ to go the parent of the current folder. If you have the following structure:
project
- public
- app_folder
-- app.js
You can use './../public' as the static folder.

What are package paths in Intern config file relative to?

In the Intern config file (default-conf.js, etc.), there's a packages section for the loader:
packages: [ { name: 'intern-selftest', location: '.' } ]
It specifies relative paths to each package. But what are those paths relative to?
the directory node is run from
the location of the config file
the location of client.html / runner.js (i.e. the intern directory)
somewhere else?
The runsauce.sh works for me but in that case, node is run from the intern directory. (A related question: does node need to be run from a certain directory?)
I've seen Intern and client paths in version 1.1.0; not sure if that's still necessary.
The paths are relative to loader.baseUrl, which in Intern 1.3 by default is the current working directory (command-line) or two levels above the client.html (browser).

Resources