You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 rivejä
1.5 KiB

3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
  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://10.23.153.10/', {useMongoClient: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. // Init App
  26. const app = express();
  27. app.set('views', path.join(__dirname, 'views'));
  28. app.set('view engine', 'pug');
  29. app.use(express.static(path.join(__dirname, 'public')));
  30. app.use(bodyParser.json()); // 使用bodyparder中间件,
  31. app.use(bodyParser.urlencoded({ extended: true }));// 使用 session 中间件
  32. app.use(session({ secret : 'IDontKnow', // 对session id 相关的cookie 进行签名
  33. resave : true, saveUninitialized: false, // 是否保存未初始化的会话
  34. cookie : { maxAge : 1000 * 60 * 60, // 设置 session 的有效时间,单位毫秒
  35. },
  36. }));
  37. // Main page
  38. let home = require("./routes/home.js");
  39. app.use("/", home);
  40. // Listen
  41. app.listen(80, function() {
  42. console.log("listen in port 80");
  43. });