-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (52 loc) · 1.52 KB
/
index.js
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
var express = require('express');
var app = express();
var connect = require('connect');
var path = require('path');
var session = require('cookie-session');
var bodyParser = require('body-parser');
var ejs = require("ejs");
var MongoClient = require('mongodb').MongoClient;
var db = null;
MongoClient.connect('mongodb://localhost:27017/hlsc',function(err,db1){
db=db1
})
var pw = "12345"
var urlencodedParser = bodyParser.urlencoded({ extended: false });
app.set('views', './views');
app.set('view engine', 'ejs');
//app.use(express.static(path.join(__dirname, '/public')));
app.get('/', function (req, res) {res.sendFile(__dirname+"/public/login.html");});
app.post('/',function(req,res){
})
app.post('/login',urlencodedParser,function(req,res){
if(req.body.pw == "12345"){
db.collection('items').find({}).toArray(function(err,doc){
if(err) throw err;
res.render('app',{
data : doc,
title : "title"
});
});
}else{
res.send('login failed');
}
})
//app.use(express.cookieDecoder());
app.use(session({
key: 'sid', // 세션키
secret: 'secret', // 비밀키
cookie: {
maxAge: 1000 * 60 * 60 // 쿠키 유효기간 1시간
}
}));
var mysql = require('mysql');
var connection = mysql.createConnection({
host :'localhost',
port : 3306,
user : 'ln',
password : 'ln',
database:'ln'
});
app.listen(process.env.PORT || 3000 , function () {
console.log('Example app listening on port ',process.env.PORT || 3000);
});