]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blob - app.js
Add welcome screen
[perso/Immae/Projets/Nodejs/Surfer.git] / app.js
1 #!/usr/bin/env node
2
3 'use strict';
4
5 var express = require('express'),
6 morgan = require('morgan'),
7 path = require('path'),
8 compression = require('compression'),
9 bodyParser = require('body-parser'),
10 lastMile = require('connect-lastmile'),
11 multipart = require('./src/multipart'),
12 files = require('./src/files.js')(path.resolve(__dirname, 'files'));
13
14 var app = express();
15 var router = new express.Router();
16
17 var multipart = multipart({ maxFieldsSize: 2 * 1024, limit: '512mb', timeout: 3 * 60 * 1000 });
18
19 router.get('/api/files/*', files.get);
20 router.put('/api/files/*', multipart, files.put);
21 router.delete('/api/files/*', files.del);
22
23 // healthcheck in case / does not serve up any file yet
24 router.get('/', function (req, res) { res.sendfile(path.join(__dirname, '/app/welcome.html')); });
25
26 app.use(morgan('dev'));
27 app.use(compression());
28 app.use(bodyParser.json());
29 app.use('/settings', express.static(__dirname + '/app'));
30 app.use(express.static(__dirname + '/files'));
31 app.use(router);
32 app.use(lastMile());
33
34 var server = app.listen(3000, function () {
35 var host = server.address().address;
36 var port = server.address().port;
37
38 console.log('Surfer listening at http://%s:%s', host, port);
39 });