index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. //by
  19. // 首页
  20. app.get('/', function (req, res) {
  21. res.redirect('/file')
  22. });
  23. // 静态网页
  24. app.use('/file', express.static('src'));
  25. // 上传完成的文件
  26. app.use('/uploadFile', express.static('upload'));
  27. // 上传页面
  28. app.post('/upload', upload);
  29. // 启动服务器
  30. var server = app.listen(3000, function () {
  31. var host = server.address().address;
  32. var port = server.address().port;
  33. console.log('Listening at http://%s:%s', host, port);
  34. });