I am learning to use Node.js. Currently, I have a folder structure that looks like the following:
index.html
server.js
client
index.html
subs
index.h
According to my current restify version (v5.2.0)
the serveStatic has been moved into plugins, so the code would be like this
server.get(
/\/(.*)?.*/,
restify.plugins.serveStatic({
directory: './static',
})
)
Syntax above will serve your static files on folder static. So you can get the static file like http://yoursite.com/awesome-photo.jpg
For some reason if you want to serve the static files under specific path like this http://yoursite.com/assets/awesome-photo.jpg for example.
The code should be refactored into this
server.get(
/\/assets\/(.*)?.*/,
restify.plugins.serveStatic({
directory: `${app_root}/static`,
appendRequestPath: false
})
)
The option appendRequestPath: false above means we dont include assets path into the file name