Static resources
- The default static resource storage directory is the root directory
static
folder
my-nodestack-app
├── src
│ ├── static
│ │ │── test.png
├── ndsk.config.js
└── package.json
-
You can customize the static file directory in the plugin
my-nodestack-app
├── images
│ ├── test.png
├── src
│ ├── plugins
│ │ │── staticFile.js
├── ndsk.config.js
└── package.json
const Path = require('node:path')
exports.plugin = {
name: 'staticFile',
register: async (server) =>{
server.route({
method:'get',
path:'/images/{name*}',
options: {
cache: {expiresIn: 60 * 1000}, //Cache 60 seconds
},
handler:(request,h)=>{
return h.file(Path.join(process.cwd(),`images/${request.params.name}`))
}
})
}
}
- The above plugin indicates that
path
starting with/images/
points to theimages
directory file in the root directory, and sets the cache to 60 seconds - Visit http://localhost:3000/images/test.png