Comments (5)
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?
from barista.
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 /admin.html#/<whatever>
, but /admin/#/<whatever>
.
Also, putting it inside another folder possible for my architecture...
(thanks for the fast answer!)
from barista.
So, first of all, routes with local segments (hash links) will never be sent to the server. Everything before the #
is the part of the URL that will be requested from your server, then it's up to you (and angular) what to do with the hash route (everything after 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 router
router.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 :-)
from barista.
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?)
from barista.
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)
from barista.
Related Issues (20)
- broken mixin helper for deep copy HOT 3
- Add request header routing HOT 2
- Calling router.first method would return false when it takes URL which contains %20s ( spaces ) HOT 2
- What about Strict Mode? HOT 2
- Error in barista 0.10 HOT 18
- Need stable release branch for submitting bugfixes HOT 1
- Id parameter can not content dots HOT 1
- What license is Barista? HOT 2
- Add namespace support
- Limiting the methods of the Resource class HOT 1
- Customizing Resources
- wrong documentation
- Adding an additional information to route HOT 1
- Generate url by name HOT 3
- Add support for HTTP PATCH method HOT 2
- Allow extra_params to be passed to .resource() HOT 2
- Match periods with a glob HOT 2
- Redirects HOT 1
- barista does not support a "bare" route HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from barista.