Node JS newbie: why do I get a 404? (angular-seed) - node.js

I'm trying NodeJS for the first time.
I'm following the hello world instructions at https://github.com/angular/angular-seed and https://github.com/thedigitalself/angular-sprout (which has the same hello world instructions for a slightly modified fork of the first one).
In both cases, I'm supposed to just run a web-server.js file that is included in the repo using Node and then navigate to http://localhost:<port>/app/index.html
This gives me a 404 error page (which is written in the web-server.js file), as does just /app/.
But if I navigate to http://localhost:<port> I get a directory listing for the filesystem directory where the web-server.js script is, which is also written in web-server.js.
Any idea why web-server.js cannot find /app/ or /app/index.html?

Make sure you run the server from your root directory.
~/angular-seed/
In here you do node scripts/web-server.js
Then you can visit
http://localhost:<PORT>/app/index.html

Related

Sails (1.2.3) gives plaintext 'Not found' (404) when main entry point is moved to a subfolder, how do I fix?

My sails.js project is also an electron.js project, and for packaging I'll need to move my main entry point to a subfolder (thanks, electron-packager) ... but here's what happens.
Before moving the entry point to a subfolder, my app works under all methods of launching, namely:
sails lift
node .
electron .
electron-forge start
Launching with the main entry point in a subfolder gives these results:
sails lift works perfectly, I can use the app 100%
All other methods of launching the app e.g. node . however, misbehaves.
"Misbehaves" = 404 plaintext "Not Found"
When I say "misbehaves" -- I'm not sure the extent of the problem. Sails lifts, it complains that it can't find its session secret, and when I load the page in a browser I get a 404 with a plaintext "Not found" message. I suspect the engine has launched but it hasn't found its app files.
Troubleshooting suggestions or a solution would be greatly appreciated.
Note that I did update package.json's "main" attribute.
Here is my package.json
I found a workaround.
Move the "real" main entry script to the top-level folder of the project (same folder as package.json).
Create a new script and put it in the subfolder, e.g. app/launcher.js. It only needs to contain one line: require('../app.js'); (presuming your "real" main entry script is app.js).
Update package.json 's main node to point at app/launcher.js
I also reported this as a bug to sails.js, but they re-flagged it as a question. :-/

React Builds- Which files go on the server? Why isn't my project deploying?

Goal: I have created the start of a React project and wish to test it on my server (hosted by goDaddy, uploading via cPanel). My app works fine in Development Mode.
Question: I have ran npm build which has created a build folder, but what files am I supposed to upload to my server? I tried putting the entire contents of the build folder on, but it still says the site is not launched. Is this because there is no index.html file generated? Currently my build folder contains: assets.json, LICENSE.txt, package.json, server.js, yarn.lock, chunks/ and public/. Is there supposed to be an html file generated? Or should these files be sufficient to deploy the website given that it works in development mode?
Thanks for bearing with me, this is the first time I have tried to deploy a React App and likely have several fundamental misunderstandings of how it works. Also if anyone is willing to chat for several minutes so I can ask a few questions about my project and react let me know - much appreciated!
Hello
Dear,
If you can try to change your package.json file and add ("homepage": "http://yourDomain/",) like this
"version": "0.1.0",
"homepage": "yourDominUrl",
Like
"homepage": "http://yourDomain/",
and
build again
npm run build
and the build folder is only should be uploaded file
Your answer is much more simple than appears: Just run npm run build, then just upload that whole folder to your GODADDY server. Importantly, you must place your index.html (or app-name.html) directly on the / public path defined by your URL's DNS. So, Top-level has your single entry point index.html that points to folder build/ to get your xyx.main.js and the xyz.main.css ...
and that's it! easy as pie

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!

Installed Node + vue-cli on AWS. But get a blank page?

Ok, learning here. Installed the default vue-cli app on AWS. I do a npm run build. When I launch the default index.html I'm served a blank page. If I go into dist, there is another index.html, that serves links to js files, but still a blank page.
I'm guessing webpack wants me to launch an index.html, but don't see how I can hit that with a browser. No errors anywhere. But no Hello World either. thanks for help.
What I'm seeing in the browser:
<!DOCTYPE html><html><head><meta charset=utf-8><title>hello-world</title><link href=/static/css/app.87e65e7c83fb67c04e58d4461a7fd8e8.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.fa7eecfb52900d1cfb0a.js></script><script type=text/javascript src=/static/js/vendor.9baeef453ba99a70f46a.js></script><script type=text/javascript src=/static/js/app.cdfbb21001bbc43de4bc.js></script></body></html>
When you npm run build Webpack should produce an index.html file along with a static/ directory that contains all of your javascript and css. The link to static/ is an absolute link (i.e. http://example.org/static). When you try to open index.html as a file, the browser will look for the /static/ folder on the root of your file system, which of course it won't find.
To run it locally you need to fire up an http server locally. One option is to cd into the directory with a terminal app and run python -m http.server. Then go to http://localhost:8000/. That should work because the root of the directory tree will be the folder from where you are serving it.
Getting it running on AWS S3 will be a matter of making sure you get the static directory in the right place and get the links pointing to it. Hard to say exactly how without knowing details of how you are organizing the site in your bucket.
You can change how the static folder is saved in the webpack config if you need to: https://vuejs-templates.github.io/webpack/static.html
You will find a folder named /dist in your project directory.Just point the index.html file within the /dist directory and rest will work fine I think. I have just done that and it's working fine.
Hope it will work.
Thanks.

Getting a directory outside symbolic links when running script nodejs

Let's assume the following example
ROOT
config
my.json
releases
today
index.js
current (symlink to today for example)
i would like to include the json file in my index.js file using a simple requirestatement, require('my.json')
The nodejs script would be launcher using node index.js or node fullpath/index.js
The problem encountered is that the require path will always resolve to releases/today/index.js instead of current/index.js. Because of this the inclusion of my json file is not correct.
The following techniques have been tried, followed by the output:
__dirname: /ROOT/releases/today
process.cwd(): /ROOT/releases/today
process.env.PWD: depending on the startup location of the script: / or /ROOT/current
require('path').resolve(__dirname)): /ROOT/releases/today
process.env.PWD doesn't always give stable results and i was wondering if there is something that has the same result.

Resources