index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var express = require('express');
  2. var app = express();
  3. var bodyParser = require('body-parser');
  4. var upload = require('./js/upload');
  5. app.use(bodyParser.json());
  6. app.use(bodyParser.urlencoded({extended: false}));
  7. /*function generateUUID() { // Public Domain/MIT
  8. var d = new Date().getTime();
  9. if (typeof performance !== 'undefined' && typeof performance.now === 'function'){
  10. d += performance.now(); //use high-precision timer if available
  11. }
  12. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  13. var r = (d + Math.random() * 16) % 16 | 0;
  14. d = Math.floor(d / 16);
  15. return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
  16. });
  17. }*/
  18. // 首页
  19. app.get('/', function (req, res) {
  20. res.redirect('/file')
  21. });
  22. // 静态网页
  23. app.use('/file', express.static('src'));
  24. // 上传完成的文件
  25. app.use('/uploadFile', express.static('upload'));
  26. // 上传页面
  27. app.post('/upload', upload);
  28. // 启动服务器
  29. var server = app.listen(3000, function () {
  30. var host = server.address().address;
  31. var port = server.address().port;
  32. console.log('Listening at http://%s:%s', host, port);
  33. });