On production servers, we use nginx
to serve static files for our Sails.js application, however in development environment we want Sails to serve static files for us. This will allow us to skip nginx installation and configuration on dev's machines.
How do I do this?
I'm going to show you how you could solve this using serve-static module for Node.js/Express.
1). First of all install the module for development environment:
npm i -D serve-static
.2). Create
serve-static
directory inside ofapi/hooks
directory.3). Create the
index.js
file in theserve-static
directory, created earlier.4). Add the following content to it:
5). Edit
config/http.js
file and add the previously defined middleware:6). Restart/run your application, e.g.
node ./app.js
and try to fetch one of static files. It should work.