Static files served by node.js on heroku - is it a good idea? [closed]

好久不见. 提交于 2019-12-08 00:51:31

问题


I have Backbone powered single page app. App consists of couple of files:

index.html
javascripts/app.js
javascripts/vendor.js
stylesheets/app.css
images/ -> image assets

I want to add prerender.io service to my app to make it SEO-friendly. The easiest way of doing this for me is to use express.js hosted on heroku:

var express = require('express');
var app = express();
app.use(require('prerender-node').set('prerenderToken', 'YOUR_TOKEN'));
// ...
app.listen(process.env.PORT || 5000);

But maybe express or actually node are not best for serving static files? Maybe heroku isn't best for serving static files? What will be best solution? What do you recommend?


回答1:


See this StackOverflow question for serving static files through expressjs: static files with express.js

You should be able to use Heroku's free dyno to handle a good bit of traffic since you're only serving static files.

I would suggest putting all of those files/folder in a "public/" directory and using this code:

var express = require('express'); 
var app = express();
app.use(express.static(__dirname + '/public'));

app.listen(process.env.PORT || 3000);



回答2:


You better use CDN for serving static files like Amazon S3.



来源:https://stackoverflow.com/questions/22297072/static-files-served-by-node-js-on-heroku-is-it-a-good-idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!