Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

69 righe
1.8 KiB

3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
  1. const cp = require('child_process');
  2. const express = require("express");
  3. const path = require("path");
  4. const mongoose = require("mongoose");
  5. const bodyParser = require("body-parser");
  6. const session = require('express-session');
  7. // codeserver = cp.execFile('sudo', [
  8. // 'code-server',
  9. // '--user-data-dir=/root/codedata',
  10. // '--auth=none',
  11. // '--bind-addr=0.0.0.0:80'
  12. // ], function(error, stdout, stderr) {
  13. // });
  14. // Link Database
  15. mongoose.connect('mongodb://root:123456@10.23.153.10', {useUnifiedTopology: true, useNewUrlParser: true})
  16. let db = mongoose.connection;
  17. mongoose.plugin(schema => { schema.options.usePushEach = true });
  18. // Check DB errors
  19. db.once('open', function() {
  20. console.log("Connected to mongoDB")
  21. })
  22. db.on('error', function(err) {
  23. console.log(err);
  24. });
  25. // codeserver = cp.execFile('sudo', [
  26. // 'code-server',
  27. // '--user-data-dir=/root/codedata',
  28. // '--auth=none',
  29. // '--bind-addr=0.0.0.0:' + 8080
  30. // ], function(error, stdout, stderr) {
  31. // console.log(error + '\n' + stdout + '\n' + stderr);
  32. // });
  33. // Init App
  34. const app = express();
  35. app.set('views', path.join(__dirname, 'views'));
  36. app.set('view engine', 'pug');
  37. app.use(express.static(path.join(__dirname, 'public')));
  38. app.use(bodyParser.json()); // 使用bodyparder中间件,
  39. app.use(bodyParser.urlencoded({ extended: true }));// 使用 session 中间件
  40. app.use(session({ secret : 'IDontKnow', // 对session id 相关的cookie 进行签名
  41. resave : true, saveUninitialized: false, // 是否保存未初始化的会话
  42. cookie : { maxAge : 1000 * 60 * 60, // 设置 session 的有效时间,单位毫秒
  43. },
  44. }));
  45. // Main page
  46. let home = require("./routes/home.js");
  47. app.use("/", home);
  48. // Listen
  49. app.listen(80, function() {
  50. console.log("listen in port 80");
  51. });