Commit 769c207b authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

initialize structure

parent 4114ee64
This diff is collapsed.
const config = {
env: process.env.NODE_ENV || 'development',
port: process.env.PORT || 3030,
jwtSecret: process.env.JWT_SECRET || 'My_secrete_key',
mongoUri: process.env.MONGODB_URI || process.env.MONGO_HOST || 'mongodb://qnaservice:qwerasdf@' + (process.env.IP || 'localhost') + ':' + (process.env.MONGO_PORT || '27017') + '/qna-service-test',
}
module.exports = config
\ No newline at end of file
{
"name": "qna-service-competition",
"version": "1.0.0",
"description": "고려대학교 세종캠퍼스 학술정보원 주최 공모전",
"main": "index.js",
"scripts": {
"dev": "node ./server/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://compmath.korea.ac.kr/gitlab/research/qna-service-competition.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"helmet": "^4.2.0",
"mongoose": "^5.10.12"
}
}
const express = require('express')
const bodyParser = require('body-parser')
// import compress from 'compression'
const cors = require('cors')
const helmet = require('helmet')
const path = require('path')
// import userRoutes from './routes/user.routes'
// import authRoutes from './routes/auth.routes'
// import postRoutes from './routes/post.routes'
const CURRENT_WORKING_DIR = process.cwd()
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// app.use(compress())
app.use(helmet())
app.use(cors())
app.use('/dist', express.static(path.join(CURRENT_WORKING_DIR, 'dist')))
// app.use('/', userRoutes)
// app.use('/', authRoutes)
// app.use('/', postRoutes)
app.use((err, req, res, next) => {
if (err.name === 'UnauthorizedError') {
res.status(401).json({
error: err.name + ': ' + err.message
})
} else if (err) {
res.status(400).json({
error: err.name + ': ' + err.message
})
console.log(err)
}
})
module.exports = app
\ No newline at end of file
const mongoose = require('mongoose')
const app = require('./express')
const config = require('../config/config')
mongoose.Promise = global.Promise
mongoose.connect(config.mongoUri, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
})
mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${config.mongoUri}`);
})
app.listen(config.port, () => {
console.info('Server started on port %s.', config.port)
})
\ No newline at end of file
This diff is collapsed.
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