Commit 5bd01525 authored by Soo Hyun Kim's avatar Soo Hyun Kim
Browse files

soo임시저장0102

parent d05bb4f0
import mongoose from 'mongoose'
const {String} = mongoose.Schema.Types
const ChatSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
interest: {
type: String,
required: true,
select: false
},
isOpen: {
type: String,
required: true,
default: 'user',
enum: ['user', 'admin', 'root']
}
}, {
timestamps: true
})
export default mongoose.models.User || mongoose.model('chat', ChatSchema)
\ No newline at end of file
import express from 'express'
import userCtrl from '../controllers/user.controllers.js'
const router = express.Router()
router.route('/api/users/signup')
.post(userCtrl.signup)
.get(userCtrl.hello)
export default router
\ No newline at end of file
import express from 'express'
import connectDb from './utils/connectDb.js'
import userRouter from './routes/user.routers.js'
connectDb()
const app = express()
app.use(express.json())
app.use(userRouter)
app.get('/', (req, res) => {
res.sendFile('../client/src/index.js')
})
app.listen(3001, () => {
console.log('Listening on port 3001')
})
\ No newline at end of file
import mongoose from 'mongoose'
import config from '../config.js'
const connection = {}
async function connectDb() {
if (connection.isConnected){
return
}
const db = await mongoose.connect(config.mongoDbUri,{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
})
connection.isConnected = db.connections[0].readyState
}
export default connectDb
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment