I have the following code:
app.js
[...] server.get(/\/docs\/public\/?.*/, restify.serveStatic({ directory: './public' })); server.listen(1337, function() { console.log('%s listening at %s', server.name, server.url); });
And I have the following file structure
app.js public/ index.html
So I try browsing:
http://localhost:1337/docs/public/index.html
and I get
{ code: "ResourceNotFound", message: "/docs/public/index.html" }
I tried with several variations, but none of them seemed to work.
I'm sure it should be something pretty obvious I'm missing
In your node application, you can use node-static module to serve static resources. The node-static module is an HTTP static-file server module with built-in caching. First of all, install node-static module using NPM as below. After installing node-static module, you can create static file server in Node.
restify is a node. js module purpose built to create REST web services in Node. restify makes lots of the hard problems of building such a service, like versioning, error handling and content-negotiation easier.
A restify server object is the main interface through which you will register routes and handlers for incoming requests.
Static files are typically files such as scripts, CSS files, images, etc... that aren't server-generated, but must be sent to the browser when requested. If node. js is your web server, it does not serve any static files by default, you must configure it to serve the static content you want it to serve.
restify
will use the directory
option as a prefix for the entire route path. In your case, it will look for ./public/docs/public/index.html
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With