-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·44 lines (35 loc) · 1.06 KB
/
index.js
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
var fs = require('fs');
var express = require('express');
var app = express();
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
var process = require('./process');
var index = fs.readFileSync('views/index.html');
app.get('/', function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(index);
});
app.post('/queue', multipartMiddleware, function(req, res) {
fs.readFile(req.files.image.path, function(err, data) {
var imageName = req.files.image.name;
if(!imageName) {
console.log("There was an error.");
res.redirect('/');
res.end();
}
else {
var newPath = __dirname + '/queue/' + imageName;
fs.writeFile(newPath, data, function(err) {
res.redirect('/queue/' + imageName);
});
}
});
});
// Route for showing files
app.get('/uploads/:file', function(req, res) {
file = req.params.file;
var img = fs.readFileSync(__dirname + '/uploads/' + file);
res.writeHead(200, {'Content-Type': 'image/jpg'});
res.end(img, 'binary');
});
app.listen(8080);