|
|
- const cp = require('child_process');
- const express = require("express");
- const path = require("path");
- const mongoose = require("mongoose");
- const bodyParser = require("body-parser");
- const session = require('express-session');
-
-
-
- // codeserver = cp.execFile('sudo', [
- // 'code-server',
- // '--user-data-dir=/root/codedata',
- // '--auth=none',
- // '--bind-addr=0.0.0.0:80'
- // ], function(error, stdout, stderr) {
- // });
-
- // Link Database
- mongoose.connect('mongodb://10.23.153.10/', {useMongoClient:true})
- let db = mongoose.connection;
- mongoose.plugin(schema => { schema.options.usePushEach = true });
-
-
- // Check DB errors
-
- db.once('open', function() {
- console.log("Connected to mongoDB")
- })
- db.on('error', function(err) {
- console.log(err);
- });
-
-
- // Init App
- const app = express();
-
- app.set('views', path.join(__dirname, 'views'));
- app.set('view engine', 'pug');
-
- app.use(express.static(path.join(__dirname, 'public')));
-
- app.use(bodyParser.json()); // 使用bodyparder中间件,
- app.use(bodyParser.urlencoded({ extended: true }));// 使用 session 中间件
- app.use(session({ secret : 'IDontKnow', // 对session id 相关的cookie 进行签名
- resave : true, saveUninitialized: false, // 是否保存未初始化的会话
- cookie : { maxAge : 1000 * 60 * 60, // 设置 session 的有效时间,单位毫秒
- },
- }));
-
-
- // Main page
- let home = require("./routes/home.js");
- app.use("/", home);
-
-
-
- // Listen
- app.listen(80, function() {
- console.log("listen in port 80");
- });
|