-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to route single static files #30
Comments
If your needs are simple, you can probably start with something like https://gist.github.com/rpflorence/701407 or https://github.com/cloudhead/node-static Are you using barista for anything else in your project? What framework are you using? |
I'm using it for geddy.js My routes are complex (REST and so on), but i'm building it with an Angular app, that only requires static assets. I didn't want the user to go to Also, putting it inside another folder possible for my architecture... (thanks for the fast answer!) |
So, first of all, routes with local segments (hash links) will never be sent to the server. Everything before the That said, you can absolutely use geddy / barista to resolve static assets. I'd probably set up a static asset controller and deliver the files that way. Something like this: define the route in your routerrouter.get('/assets/*filename').to('Assets.deliver') then in your assets controller (app/controllers/assets maybe?):// include fs and path from node
var fs = require('fs'),
path = require('path');
// your geddy `Assets.deliver` method
this.deliver = function (req, resp, params) {
// build the filepath from the request params
var filePath = path.join(__dirname, params.filename);
// find the file on your server
var stat = fs.statSync(filePath);
// write the response headers
resp.writeHead(200, {
'Content-Type': 'application/whatever',
'Content-Length': stat.size
});
// create a read stream and pipe it to the client
var readStream = fs.createReadStream(filePath);
readStream.pipe(resp);
} Keep in mind that's an extremely simple example with zero security considerations or testing, but should at least put you on the right track. Also don't be afraid to ask these types of questions in the #geddy room on IRC! They're a friendly bunch :-) |
That was my plan B haha Security is not the problem, since all my REST endpoints will be protected, allowing the user to load the admin page is the best he can do if trying to invade... Will do that, thanks! (where is the IRC room?) |
This is a good, free, web-based IRC client: https://www.irccloud.com After you're connected, join the #geddy channel (which is on Freenode, if it asks) |
I need to route a single static file, like:
router.get('/admin').to('/admin.html');
Is it possible with barista?
The text was updated successfully, but these errors were encountered: