forked from manikjindal/fileUploadServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
54 lines (46 loc) · 1.43 KB
/
app.js
File metadata and controls
54 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Module dependencies
*/
var express = require('express');
var http = require('http');
var path = require('path');
var routes = require('./routes');
var config = require('./config');
var app = express();
// all environments
app.set('port', config.port);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
// base path for the application
var basePath = '/'; // default base-path
if (config.generateRandomBasePath) {
var randomString = Math.floor((1 + Math.random()) * 0x100000000).toString(16).substring(1); // 8-digit random hex-number
basePath = '/' + randomString;
} else if (config.basePath) {
basePath = config.basePath;
}
// upload path
var uploadPath = basePath;
if (uploadPath.charAt(uploadPath.length - 1) != '/') {
uploadPath += '/';
}
uploadPath += 'doUpload';
// Routes
app.get(basePath, routes.index);
routes.uploadPath = uploadPath;
app.post(uploadPath, routes.doUpload);
// start server
http.createServer(app).listen(app.get('port'), function(){
var port = app.get('port');
console.log('Express server listening on port ' + port + '; application path: ' + 'http://127.0.0.1:' + port + basePath);
});