서주원

set routings

const express=require('express')
const router=express.Router()
module.exports=router
\ No newline at end of file
const express=require('express')
const router=express.Router()
module.exports=router
\ No newline at end of file
const express=require('exress')
const router=express.Router()
router.use('/user',require('./user'))
router.use('/deck',require('./deck'))
router.use('/card',require('./card'))
module.exports=router
\ No newline at end of file
const express=require('express')
const router=express.Router()
const signUp=require('./signUp')
const login=require('./login')
const express=require('express')
const session=require('express-session')
const findById=require('../../database/user/findById')
const mysql=require('mysql')
const bcrypt=require('bcrypt-nodejs')
const dbconfig=require('../../dbconfig')
const connection=mysql.createConnection(dbconfig)
connection.connect()
exports.SignUp=(req,res)=>{
const userId=req.body.userId
const password=req.body.password
const DataCheck=()=>{
return new Promise((resolve,reject)=>{
if(!userId || !password){
return reject({
code: 'request_body_error',
message: 'request body is not defined'
})
}
else resolve()
})
}
const SignUp=()=>{
const user=findById(userId)
if(!user){
const hash=bcrypt.hashSync(password,bcrypt.genSaltSync(10),null)
connection.query(`insert into user (userId,password) values (${userId},${hash});`,(err,results,fields)=>{
if(err){
throw err
}
else{
console.log(results)
}
})
}
else{
return reject({
code:'User_already_exists',
message:'User already exists'
})
}
}
DataCheck()
.then(SignUp)
.then(()=>{
return res.status(200).json({userId:userId})
})
.catch((err)=>{
console.log(err)
res.status(500).json(err.message||err)
})
}
\ No newline at end of file
......@@ -9,6 +9,8 @@ const morgan=require('morgan')
const cheerio=require('cheerio')
const mysql=require('mysql')
require('dotenv').config()
app.use('/api',require('./api'))
const dbconfig=require('dbconfig')
const app=express()
app.use(morgan('[:date[iso]] :method :status :url :response-time(ms) :user-agent'))
......@@ -23,13 +25,7 @@ app.use(function (req, res, next) {
next()
})
const connection=mysql.createConnection({
host:process.env.DB_HOST,
user:process.env.DB_USER,
password:process.env.DB_PASSWORD,
database:'user',
port:''
})
const connection=mysql.createConnection(dbconfig)
let allCards=[]
fs.readFile('cardskoKR.json',(err,data)=>{
......@@ -50,8 +46,10 @@ app.get('/main',(req,res)=>{
if(!req.session.sid)
res.redirect('/login')
else {
fs.readFile('./views/main')
fs.readFile('./views/main',(err,data)=>{
res.writeHead(200, {'Content-Type': 'text/html'})
res.end(data)
})
}
})
......
const express=require('express')
const router=express.Router()
module.exports=router
\ No newline at end of file
const express=require('express')
const router=express.Router()
module.exports=router
\ No newline at end of file
const express=require('express')
const router=express.Router()
router.use('/user',require('./user'))
router.use('/deck',require('./deck'))
router.use('/card',require('./card'))
module.exports=router
\ No newline at end of file
const mysql=require('mysql')
const dbconfig=require('../../dbconfig')
exports.findById=(userId)=>{
const connection=mysql.createConnection(dbconfig)
connection.connect()
connection.query(`select * from user where userId=${userId}`,(err,result,fields)=>{
if(err){
throw err
}
else{
return result
}
})
}
const express=require('express')
const router=express.Router()
app.get
module.exports=router
\ No newline at end of file
require('dotenv').config()
const mysql=require('mysql')
module.exports={
host:process.env.DB_HOST,
user:process.env.DB_USER,
password:process.env.DB_PASSWORD,
database:'WhoAreYou',
port:process.env.DB_PORT
}
\ No newline at end of file