mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30: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
+19
@@ -0,0 +1,19 @@
|
|||||||
|
FROM node
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json yarn.lock ./
|
||||||
|
COPY server/package.json ./server/
|
||||||
|
RUN yarn install --frozen-lockfile --production
|
||||||
|
|
||||||
|
WORKDIR /app/server
|
||||||
|
|
||||||
|
COPY server/src ./src
|
||||||
|
COPY server/quests ./quests
|
||||||
|
COPY server/swagger.yaml .
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV HOST=0.0.0.0
|
||||||
|
ENV PORT=3000
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD [ "yarn", "start" ]
|
||||||
@@ -1,5 +1,16 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
|
app:
|
||||||
|
image: lancatlin/linux-odyssey-server
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- '3000:3000'
|
||||||
|
links:
|
||||||
|
- db
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
environment:
|
||||||
|
- MONGO_URL=mongodb://db:27017/odyssey-test
|
||||||
db:
|
db:
|
||||||
image: mongo
|
image: mongo
|
||||||
restart: always
|
restart: always
|
||||||
|
|||||||
@@ -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 mongoose from 'mongoose'
|
||||||
|
import config from './config.js'
|
||||||
|
|
||||||
export default async function connectDB() {
|
export default async function connectDB() {
|
||||||
try {
|
try {
|
||||||
await mongoose.connect('mongodb://localhost:27017/odyssey-test')
|
await mongoose.connect(config.db)
|
||||||
console.log('Connected to MongoDB')
|
console.log('Connected to MongoDB')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
|
|||||||
+3
-3
@@ -8,9 +8,9 @@ import socketServer from './api/socket.js'
|
|||||||
import connectDB from './db.js'
|
import connectDB from './db.js'
|
||||||
import apiRouter from './api/routes/index.js'
|
import apiRouter from './api/routes/index.js'
|
||||||
import loadAndUpdateQuests from './utils/quest.js'
|
import loadAndUpdateQuests from './utils/quest.js'
|
||||||
|
import config from './config.js'
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const port = 3000
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const server = http.createServer(app)
|
const server = http.createServer(app)
|
||||||
socketServer(server)
|
socketServer(server)
|
||||||
@@ -28,8 +28,8 @@ async function main() {
|
|||||||
|
|
||||||
app.use('/api/v1', apiRouter)
|
app.use('/api/v1', apiRouter)
|
||||||
|
|
||||||
server.listen(port, () => {
|
server.listen(config.port, config.host, () => {
|
||||||
console.log(`Server listening at http://localhost:${port}`)
|
console.log(`Server listening at http://${config.host}:${config.port}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user