- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path..ts
More file actions
Latest commit
77 lines (77 loc) · 3.67 KB
/
Copy path..ts
File metadata and controls
77 lines (77 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
console.time(`time`);import"reflect-metadata";
import{createConnection}from"typeorm";
import*asexpressfrom"express";
import*asbodyParserfrom"body-parser";
import{Request,Response}from"express";
import*assessionfrom"express-session";
import*aspathfrom"path";
import*ascookieParserfrom"cookie-parser";
import*asschedulefrom"node-schedule";
import{R,O}from"./src/routes";
import{Tag}from"./src/util/tag";
import{T}from"./src/util/tool";
import{M}from'./src/migration/middlewares';
import{Config}from"./config";
constS=require("./src/util/websocket");
constN=require('nedb-session-store')(session);
constFlash=require('connect-flash')
createConnection().then(asyncc=>{consta=express();
a.use(bodyParser.json());Tag.Init(c.name);
constt=()=>{
schedule.scheduleJob('*/15 * * * *',()=>{
T.deleteAll(Config.upload);
T.deleteOne(Config.dbLog);
});
};t();//每隔15min删除一次临时文件
a.use(session({
name:Config.session.name,secret:Config.session.secret,cookie:Config.session.cookie,//期限毫秒,25min,path:'/',secure:true
resave:true,rolling:true,saveUninitialized:false,store:newN({filename:Config.dbLog})
//url:'mongodb://localhost/blog',store:new MongoStore({host:'localhost',port:27017,db:'test'}),proxy:true// 'path_to_nedb_persistence_file.db'
}));a.use(bodyParser.json({limit:Config.jsonLimit}));a.use(bodyParser.urlencoded({extended:false}));a.use(cookieParser());
a.all((req,res,next)=>{res.header('Access-Control-Allow-Methods','GET,PUT,POST,DELETE');res.header('Access-Control-Allow-Credentials',false);
res.header('Access-Control-Allow-Origin',req.headers.origin);res.locals.session=req.session;next();});a.use(Flash());
R.forEach(v=>{
(aasany)[v.m](v.r,v.w,(req:Request,res:Response,next:Function)=>{
constr=(new(v.casany))[v.a](req,res,next);
if(rinstanceofPromise){
r.then(r=>r!==null&&r!==undefined?res.send(r):undefined).catch(e=>next(e));
}elseif(r!==null&&r!==undefined){
res.json(r);
}
});
});
O.forEach(v=>{
(aasany)[v.m](v.r,(req:Request,res:Response,next:Function)=>{
constr=(new(v.casany))[v.a](req,res,next);
if(rinstanceofPromise){
r.then(r=>r!==null&&r!==undefined?res.send(r):undefined).catch(e=>next(e));
}elseif(r!==null&&r!==undefined){
res.json(r);
}
});
});
//a.set('views',path.join(__dirname,'www'));
S.init(awaita.listen(Config.port,"0.0.0.0",
()=>{console.log(`ExServer http://localhost:${Config.port} to see`);}));
a.use(express.static(path.join(Config.upload)));
a.use(express.static(path.join(Config.pic)));
a.use(express.static(path.join(Config.view)));//a.set("view cache",true);
a.set('view engine','ejs');
a.get('/logout',M.prototype.checkLogin,(req,res)=>{
req.flash("err","退出成功!");
req.session.destroy(function(err){
if(err){console.log(err)}else{returnres.redirect('/');}
})
});
a.get('/x',M.prototype.checkLogin,async(req,res)=>{
res.send(awaitTag.parseHtml(req.query.a,
req.query.b,req.query.c,req.query.d,req.query.e,req.query.f))
})
//a.all('/inapi/*', (req,res)=>{}
// var pathname=url.parse(req.url).pathname;
//let s=await ;//insert new users for test
// await c.manager.save(c.manager.create(TAdmin,{
// username:"Phantom1",password:"e30e7efb40e0de61511dae9173af17b6",photo:"",name:"Phantoms"
// }));
console.timeEnd(`time`);
}).catch(e=>console.log(e));