Skip to content

Commit

Permalink
Change default backend port to 9006
Browse files Browse the repository at this point in the history
Also update the backend code to detect the hostname automatically so
that the bound port is only configured in Gruntfile.
Bind only 127.0.0.1 by default and try to automatically open the browser
on that page!
Fixes #69
  • Loading branch information
bago committed Dec 4, 2015
1 parent e965966 commit c932969
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ module.exports = function(grunt) {
express: {
dev: {
options: {
port: 9000,
port: 9006,
showStack: true,
hostname: '*',
hostname: '127.0.0.1',
open: true,
bases: ['.'],
server: 'backend/main.js'
}
Expand Down
11 changes: 6 additions & 5 deletions backend/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));

var listFiles = function (options, callback) {
var listFiles = function (req, options, callback) {

var files = [];
var counter = 1;
Expand All @@ -29,20 +29,22 @@ var listFiles = function (options, callback) {
callback(files);
};

var uploadHost = req.protocol + '://' + req.get('host');

fs.readdir(options.uploadDir, _.bind(function (err, list) {
_.each(list, function (name) {
var stats = fs.statSync(options.uploadDir + '/' + name);
if (stats.isFile()) {
var file = {
name: name,
url: options.uploadHost + options.uploadUrl + '/' + name,
url: uploadHost + options.uploadUrl + '/' + name,
size: stats.size
};
_.each(options.imageVersions, function (value, version) {
counter++;
fs.exists(options.uploadDir + '/' + version + '/' + name, function (exists) {
if (exists)
file.thumbnailUrl = options.uploadHost + options.uploadUrl + '/' + version + '/' + name;
file.thumbnailUrl = uploadHost + options.uploadUrl + '/' + version + '/' + name;
finish();
});
});
Expand All @@ -57,12 +59,11 @@ var uploadOptions = {
tmpDir: '.tmp',
uploadDir: './uploads',
uploadUrl: '/uploads',
uploadHost: 'http://127.0.0.1:9000',
imageVersions: { thumbnail: { width: 90, height: 90 } }
};

app.get('/upload/', function(req, res) {
listFiles(uploadOptions, function (files) {
listFiles(req, uploadOptions, function (files) {
res.json({ files: files });
});
});
Expand Down

0 comments on commit c932969

Please sign in to comment.