GithubHelp home page GithubHelp logo

Comments (5)

kieran avatar kieran commented on June 18, 2024

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.

ivanseidel avatar ivanseidel commented on June 18, 2024

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.

kieran avatar kieran commented on June 18, 2024

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.

ivanseidel avatar ivanseidel commented on June 18, 2024

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.

kieran avatar kieran commented on June 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.