
About one and a half years ago it became necessary to have a small static site of three pages and a couple of dozen. At that moment, the MSDN subscription was active and the simplest solution was to create WebRole right in the studio, put static there and do deployment using the standard features of Visual Studio. A year has passed, the subscription is over, the forecast payment for the use of Azure resources was 5,000 rubles per month. It seemed to me that this was a search for a three-page site and the search for an alternative began. Criteria: free of charge, ease of configuration and the ability to simply transfer the site as it is without completions.
Amazon S3 seemed like the most obvious option. The stumbling block was the process of registering a free subscription with AWS. Almost a month I unsuccessfully entered the verification code from the phone. In some cases, the call simply did not exist, but more often than not the code was not accepted. The
Heroku service caught my eye, and the simplicity of registration was very appealing (after a month of trying to register on AWS).
Since the service is popular, there have already been projects for static hosting. Almost all of them were implemented in Ruby. Example:
github.com/jamiew/heroku-static-site and
devcenter.heroku.com/articles/static-sites-ruby . With the use of these solutions, problems have arisen: I have little knowledge of Ruby and in order for everything to work it was necessary to significantly improve the existing structure of the site.
The next step was an attempt to use Django. The structure of the site could no longer be changed, but there were immediately minuses - many files that are not directly connected with the site. Plus there were problems with the launch in the release. In general, configuring Django cannot be called simple, for a person who has worked a little with Django and understands only in Python.
')
The configuration of Django took about a day, for unknown reasons, redirect did not work from / to index.html, but when reading manuals, everything gradually settled down. Then one person, after asking how to set up a redirect, asked - “Why do you need Django? Everything can be made easier with Node.js.
Before that, I only heard about this server, but never used it. Implementing a static site using
@d_bud took only 20 minutes (with deployment). All implementation code:
Web.js
var express = require('express'); var app = express(); var path = require('path'); app.use(express.static(path.join(process.cwd(), 'source'))); console.log(process.env.PORT || 5000); app.listen(process.env.PORT || 5000);
package.json
{ "name": "node-example", "version": "0.0.1", "dependencies": { "express": "3.1.x" }, "engines": { "node": "0.10.x", "npm": "1.2.x" } }
All that was required was to put my static site in the source folder and fix some old broken links to the pictures. Having looked for such a simple google solution, nothing similar in simplicity was given out, so I decided to write this article + to issue a
repository on github . I hope that this will be useful to someone who, like me, will need to quickly and free of charge lay out static.
PS: In general, using node.js for statics will allow you to quickly transfer it. In order to raise the site on the machine, it is enough to install node.js and execute two commands in the root folder:
npm install node web.js