mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
Add config.js, dockerfile
This commit is contained in:
1 parent
4ffdb5d627
commit
2dffd2f74d
5 files changed
+48
-4
No files matched your search
@@ -0,0 +1,13 @@
|
||||
function get(key, defaultValue) {
|
||||
const value = process.env[key]
|
||||
if (value != null) {
|
||||
return value
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
export default {
|
||||
host: get('HOST', 'localhost'),
|
||||
port: get('PORT', 3000),
|
||||
db: get('MONGO_URL', 'mongodb://localhost:27017/odyssey-test'),
|
||||
}
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
import mongoose from 'mongoose'
|
||||
import config from './config.js'
|
||||
|
||||
export default async function connectDB() {
|
||||
try {
|
||||
await mongoose.connect('mongodb://localhost:27017/odyssey-test')
|
||||
await mongoose.connect(config.db)
|
||||
console.log('Connected to MongoDB')
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
|
||||
+3
-3
@@ -8,9 +8,9 @@ import socketServer from './api/socket.js'
|
||||
import connectDB from './db.js'
|
||||
import apiRouter from './api/routes/index.js'
|
||||
import loadAndUpdateQuests from './utils/quest.js'
|
||||
import config from './config.js'
|
||||
|
||||
async function main() {
|
||||
const port = 3000
|
||||
const app = express()
|
||||
const server = http.createServer(app)
|
||||
socketServer(server)
|
||||
@@ -28,8 +28,8 @@ async function main() {
|
||||
|
||||
app.use('/api/v1', apiRouter)
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`Server listening at http://localhost:${port}`)
|
||||
server.listen(config.port, config.host, () => {
|
||||
console.log(`Server listening at http://${config.host}:${config.port}`)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user