OpenShift can not find the css and js files

advertisements

When running my openshift app none of the CSS or javescript files are loading.

I have specified the directory in the server.js:

app.use(express.static(__dirname));

In the index.html I have specified the location of the folders:

<link rel="stylesheet" href="style.css" type="text/css" media="screen">
<script src = "controllers/controller.js"></script>

The structure of the folder looks like:

mytest
├── README.md
├── controllers
│   └── controller.js
├── deplist.txt
├── index.html
├── node_modules
├── package.json
├── server.js
└── style.css

When I open the website and open the developer console in chrome I get the following errors:

http://mytest-jamestreasure.rhcloud.com/controller.js 404 Not Found

http://mytest-jamestreasure.rhcloud.com/controllers/controller.js 404 Not Found

I'm not aware of anything else that needs to be added.

Link to the my openshift: http://mytest-jamestreasure.rhcloud.com/


Your construct for defining static content access seems to be correct. Make sure that you are using it with your app context though, e.g.:

myApp.app.use(express.static(__dirname));

Such a problem could be revealed either locally when trying to run the server.js or using rhc tail mytest to check the OpenShift remote logs.


I would also recommend using a dedicated directory for static content that is meant to be used publicly, rather than exposing everything:

app.use(express.static(__dirname + '/public'));