Preferred way to serve static pages?

628 views
Skip to first unread message

Voltron

unread,
Apr 18, 2012, 7:16:36 AM4/18/12
to Express
Is there a preferred Express.js way to serve static pages? I intended
to load the pages depending on the users locale manually as such:

fs.readFile(__dirname + '/static/en/index.html', 'utf8', function(err,
text){
response.send(text);
});

How do others take care of this issue?

Thanks

Oleg Efimov

unread,
Apr 18, 2012, 9:46:29 AM4/18/12
to expre...@googlegroups.com
Use Nginx or other reverse proxy to serve static files.

среда, 18 апреля 2012 г., 15:16:36 UTC+4 пользователь Voltron написал:

Paul Vencill

unread,
Apr 18, 2012, 10:00:08 AM4/18/12
to expre...@googlegroups.com
Is there a reason to not simply put them in the /public folder and let the express.static middleware handle it?


--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.


Voltron

unread,
Apr 18, 2012, 12:22:28 PM4/18/12
to Express
The reason is that I want to server the files based on the users
locale, taking the example:
__dirname + '/static/en/index.html'. This will server the english
version of the file. I thought there was some middleware for it

Wes Freeman

unread,
Apr 18, 2012, 10:15:39 AM4/18/12
to expre...@googlegroups.com
I agree.

app.configure('development', function(){
  app.use(express.static(__dirname + '/public'));
});

Voltron

unread,
Apr 18, 2012, 5:50:46 PM4/18/12
to Express
? I am confused. I already am using the static middleware to serve CSS
and JS files. I want to serve the static HTML pages depending on a
route, so what exactly are ypu agreeing to Wes?

Anyway, I think I have found something, I just make calls like this in
the individual controllers

res.sendfile(__dirname + '/index.html');
res.sendfile(__dirname + '/de/index.html');
res.sendfile(__dirname + '/fr/foo.html');

On Apr 18, 4:15 pm, Wes Freeman <freeman....@gmail.com> wrote:
> I agree.
>
> app.configure('development', function(){
>   app.use(express.static(__dirname + '/public'));
>
> });
>

tjholowaychuk

unread,
Apr 18, 2012, 8:16:20 PM4/18/12
to expre...@googlegroups.com
res.sendfile() is equivalent to static(), but for dynamic use so yup there's nothing wrong with that
> >> express-js+unsubscribe@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/express-js?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Express" group.
> > To post to this group, send email to expre...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > express-js+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages