Reputation: 25542
I have created a static route like this:
"use strict";
var StaticPlugin = {
register: function (server, options, next) {
server.route([
{
method: 'GET',
path: '/public/{path*}',
config: {
auth: false,
description: 'Static assets',
handler: {
directory: {
path: '../public',
index: false,
listing: false
}
}
}
}
]);
return next();
}
};
StaticPlugin.register.attributes = {
name: 'StaticPlugin',
version: '1.0.0'
};
module.exports = StaticPlugin;
I register the plugin, but when I attempt to try to load a static JS file (going to be used to serve static js libraries), I get a 404 error.
The url I am trying to hit is http://localhost:3000/public/javascripts/mylib.js
Upvotes: 0
Views: 2499
Reputation: 42048
In your configuration the path is relative to the directory where the process is running. If this plugin is in a subdirectory and you start the server in the main directory, then the path will be incorrect. Either use a path that is relative to the project root, or use Path.join()
in conjunction with __dirname
, eg:
var Path = require('path');
Path.join(__dirname, '../public')
Upvotes: 4