OPENUI5 Project MVC + Node.js - node.js

I do structure the project OpenUI5 MVC structure with node.js as following:
My App.js file:
My index.html file:
However, it always produces the following error:
[ERROR] XML Parsing Error: mismatched tag. Expected: </meta>.
Location: http://localhost:1024/
Line Number 6, Column 3:
[ERROR] Error: resource sap/ui/demo/walkthrough/view/App.view.xml could not be loaded from ./view/App.view.xml. Check for 'file not found' or parse errors. Reason: Not Found
If I try to move the "view" folder into the "public" folder ==> the project works well. I don't know what causes the issue above. Any assistance in clarifying this error is greatly appreciated.

As you set with app.use(express.static('public') the access path to the root path (/), all static file loads (to which the UI5 source files belongs to) are redirected to /public. W/o having the files in the /public folder you get a load failure.
If you wanna have a specific path which you can use in your app to the static file content, than you can define a mounting path, e.g. app.use('/static', express.static('public').

Related

Failed to load resource: the server responded with a status of 404 (Not Found) Express

This file contain the file structure
This file contains the directory settings
While trying to add static images to the home.ejs folder i am constantly getting this error:-
Failed to load resource: the server responded with a status of 404 (Not Found)
I tried to use the app.use(express.static('public')) but the issue still persist.
This is the path i used:
assets/img/hero.jpg
I cannot figure out how to solve this issue and is there is something wrong with file structure or i made mistake while referencing the file name.
First we need to set the path
app.set('/views',path.join(__dirname,'/views'))
then we can use image by using this path:
img/hero.jpg

Serving static files with Express.js on heroku. Where do files reside in Heroku?

The issue is Heroku can not find the files of my node project. This prompts the 404 Not found error. The question is how does the generic node Heroku file structure look like? If so, where do the files of my project actually reside in the heroku?
The scenario:
With the express library, I put all files needed to serve a frontend template, in a folder called 'public'. The absolute path leading to 'public' is needed and'_dirname' is the variable that contains that.
app.use(express.static(_dirname+'/public');
Now, Heroku always makes a GET request to the root of the application. As a response I send the
index.html file as the starting template. I also provide its absolute path as '{root:_dirname}'.
app.get('/', function(req, res) {
res.sendFile('public/index.html'{root:_dirname});
});
When the server is run, I get a 404 Not found error. Which means Heroku cannot find the files.
Heroku root folder is named app/. So as expected, providing the local '_dirname' is wrong since the application is now running on Heroku server not locally.
2020-09-10T15:28:12.127567+00:00 app[web.1]: Error: ENOENT: no such file or directory, stat '/app/C:/Users/...
But, pointing at the public folder alone(only /public), assuming app/ is root, still prompts the 404 error not found.
2020-09-10T15:31:23.630358+00:00 app[web.1]: Error: ENOENT: no such file or directory, stat '/index.html'
The Question
Which leads to the question, what does heroku file structure look like? where do project files reside in the heroku file structure, so i can provide the correct path on the GET request?
My file structure
After Bergur suggestion:
It prompts a 404 Not found. However, the path is now theoretically correct.
This is what I changed:
app.use(express.static(path.join(__dirname+'/public')));
app.get('/', function(req, res) {
res.sendFile('index.html',{root:__dirname+'/public'});
});
The 404 error comes from the 'app.get('/,function(req,res){});'. Without this handler, my heroku application shows a 'cannot GET' message on the template.
Have you tried to log out the full path just to see if there's something off?
I have several heroku projects with nodejs and react/vue/angular dist folder without problems.
I would change your code a little bit to:
use nodes __dirname
Use path.join instead of inserting the '/' yourself. It might cause some problems.
So final version might look like:
app.use(express.static(path.join(__dirname, 'public')));
This assumes the project structure is
-index.js
-public/index.html
There should be no need to use sendFile, serving the public folder is enough. Just make sure that the public folder is being deployed/pushed to heroku.
If you share with us your folder/project structure we might help you you better.

node.js website deployed to Azure - 404 failed to load a .json resource

I have a node.js Web App in Azure,
the site loads the index.html, the css, images, etc. but the JS search functionality doesn't initialize,
I did an F12 inspection in Chrome and saw this error
[domain].azurewebsites.net/data/policies.json Failed to load resource: the server responded with a status of 404 (Not Found)
in the Azure console I can see the file list
> cd public
D:\home\site\wwwroot\public
> cd data
D:\home\site\wwwroot\public\data
> ls
D:\home\site\wwwroot\public\data
policies.json
according to the folder/file structure (everything is in the /public folder) I have made a configuration change as follows
/ = "site/webroot/public"
the folders are laid out like this
/public/index.html
/public/data
/public/js
/public/css
etc
Without the config setting the website doesn't see /public as the root folder, so it doesn't find the index.html and nothing loads.
So the site loads, which is great,
the images and css load, which is great
but it says it can't find the .json file in the data folder?
(and using the console the file is definitely there!)
please advise.
You need to set the JSON MIME type in web.config
This link explains how to fix it:
http://blogs.msdn.com/b/africaapps/archive/2013/06/07/how-to-serve-static-json-files-from-a-windows-azure-website.aspx

NodeJitsu error: Error: ENOENT, stat '/opt/run/snapshot/

My app’s folder structure for NodeJitsu is as follows (i.e., when i do a jitsu deploy, I'm in the folder that contains "server.js" - i.e., the "server" folder).
Root server
|___server.js
|___package.json
client
|___www
|___index.html
|___css
|___js
|___etc.
So at the root is the folder "server", containing the starting script, “server.js”. Then there’s a folder called “client”, parallel to "server", with a folder within that called “www”, and within “www” is the main “index.html”.
In my “server.js” file, I have the following code:
app.get(‘/’, function(req,res)
{
var aPath = path.resolve(“../client/www/”, “index.html”);
res.sendFile(aPath);
});
I don’t have a app.use(express.static(__dirname + '/somefolder'). And when I start the app, I get this error:
Error: ENOENT, stat '/opt/run/snapshot/client/www/index.html'
My process.cwd() is /opt/run/snapshot/package. Obviously the above path isn’t pointing to the location where “index.html” resides. But I thought the way I do the path.resolve(…) should point to “index.html”. I can’t see where the problem is. If “server.js” is in the root, then to get to “index.html”, which is in “client/www/index.html”, then I should need to write “../client/www”, relative to the excuting script, to get to “index.html”, right?.
Do you have any insights as to where the path is not set up correctly? What should /opt/run/snapshot/ be pointing to? Or, what changes do I need to make in the get(‘/’) handler to correctly point to my “index.html”?
EDIT
I incorrectly drew the folder structure. Now it's correct.
I also turned off the app.get() and turned on the app.use(express.static(__dirname + '/../client/www/'). But to no avail: now i get a Cannot GET / error.
What I'm ultimately after is to have the "server.js" file be the Node server that, mostly, just serves AngularJS HTML files to the browser, with attendant images, stylesheets, etc., from the "client" folder. This is the server's main role, with an additional role of authenticating the app's users, employing the very nice Satellizer module. And that's it. I have a MongoDB attached, but otherwise this is a very common and straightforward Node.js server app.
Thanks!
Try it without rooting, resolving and log out to double check:
// notice no leading / which is root. __dirname should be the dir of current file running
var staticPath = path.resolve(__dirname, '../client/www');
console.log(staticPath);
Then pass that into express.static
app.use(express.static(staticPath);
I would probably recommend following the layout and convention of express generated apps with app in the root and static files under public
/public
<static files>
app.js
Then do what the generated app does:
app.use(express.static(path.join(__dirname, 'public')));

Using RequireJS in a multipage application

we have a multipage application with below structure:
ApplicationModule is the root folder that contains all application logical modules,like Usermanagement and others like below:
/ApplicaationModules/UserManagement
//inside userManagement folder we have html pages and their corresponding .js(main)files
//so we have like
login.html and login.js
Login.js in turn requires/loads all script files that are required to execute the logic for the page, so it's configuration is like below:
require.config({
paths: {
'jquery': '../../Scripts/jquery',
'appSessionManager': '../../Scripts/ApplicationSessionManager',
'appBasePage': '../../Scripts/ApplicationBasePage',
'initServices': '../../IntegrationServices/Eservices/EservicesUserManagementService/Authenticate',
'smUtility': '../../Scripts/SmartServicesUtility',
}});
require(['appSessionManager', 'appBasePage', 'initServices', 'smUtility', 'jquery'],
function (sessionManagerRef, basePageRef, eservicesRef, utilityRef)
{
$(document).ready(function () {
//Here is the page code that uses other libraries like appSessionManager, appBasePage and others.
});
});
NOW, before moving to production, we want to use Optimizer so that all required files should be concatenated and minified as a single file.
Standing inside UserManagement folder, we run following command for the optimizer:
node ../../r.js -o name=Login out=optimize.js
BUT it is giving us the below error:
Tracing dependencies for: Login
Error: ENOENT, no such file or directory 'D:[some application path]\ApplicationModules\UserManagement\appSession
Manager.js'
In module tree:
Login
Error: Error: ENOENT, no such file or directory 'D:[some application path]\ApplicationModules\UserManagement\app
SessionManager.js'
In module tree:
Login
at Object.fs.openSync (fs.js:427:18)
Error is clear as for SessionManager.js file, it is trying to find it inside usermangement folder but I want it to look for this file inside Scripts folder as mentioned in config Paths of login.js file.
I will highly appreciate if someone can help us out on this.

Resources