Skip to content

Commit

Permalink
feat: Add update management routes (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsluph authored Sep 18, 2024
1 parent c5fa909 commit f26dffe
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 23 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
data
node_modules
.env*
46 changes: 36 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
services:
app:
#build: .
qbit:
image: lscr.io/linuxserver/qbittorrent:latest
container_name: qbit
restart: unless-stopped
networks:
- qbit-net
environment:
- WEBUI_PORT=8080
- PUID=1000
- PGID=1000
ports:
# qBittorrent WebUI is exposed by vuetorrent-backend service
# - "8080:8080"

# qBittorrent ports, NAT port forwarding required for them to work
- "6881:6881"
- "6881:6881/udp"
volumes:
- "./data/qbittorrent:/config"
- "./data/downloads:/downloads"
- "./data/torrents:/torrents"

vuetorrent-backend:
# build: .
image: ghcr.io/vuetorrent/vuetorrent-backend:latest
container_name: vuetorrent-backend
restart: unless-stopped
networks:
- qbit-net
environment:
- CONFIG_PATH=/config
- PORT=3000
- QBIT_BASE=http://host.docker.internal:8080
- VUETORRENT_PATH=/vuetorrent
# Backend port needs to match qbit one to avoid "Host header validation" issues
- PORT=8080
- QBIT_BASE=http://qbit:8080
- RELEASE_TYPE=stable # Use "dev" for nightly releases
# Only enable if using self-signed certificates
# - USE_INSECURE_SSL=true
# host.docker.internal isn't available on Linux so we must include it manually
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "3000:3000"
- "8080:8080"
volumes:
- "./data/config:/config"
- "./data/vuetorrent:/vuetorrent"

networks:
qbit-net:
driver: bridge
100 changes: 100 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dotenv": "^16.4.5",
"express": "^4.21.0",
"http-proxy": "^1.18.1",
"jszip": "^3.10.1",
"morgan": "^1.10.0"
},
"devDependencies": {
Expand Down
40 changes: 28 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import cors from 'cors'
import { config } from 'dotenv'
import express from 'express'
import morgan from 'morgan'
import path from 'path'
import authMiddleware from './middlewares/auth.js'
import configRouter from './routers/config/index.js'
import qbitRouter from './routers/qbit/index.js'
import { checkForUpdate } from './routines/update.js'
import { assert_env } from './utils.js'

config()
Expand All @@ -17,29 +17,45 @@ const app = express()

const PORT = process.env.PORT || 3000

// Middlewares
app.use(morgan('tiny'))
app.use(cors({ origin: true, credentials: true }))
app.use(express.json())
app.use(cookieParser())

// Routers
app.use('/api', qbitRouter)
app.use('/config', authMiddleware, configRouter)
app.use(express.static(path.join(process.env.VUETORRENT_PATH, 'public')))

// Routes
app.get('/ping', async (req, res) => {
res.send('pong')
})
app.get('/update', authMiddleware, async (req, res) => {
try {
res.send(await checkForUpdate())
} catch (err) {
console.error(err)
res.status(500).send('Failed to update')
}
})

// WebUI
app.use(express.static('/vuetorrent/vuetorrent/public'))
app.use(async (req, res) => {
res.status(404).send('Unable to find vuetorrent installation, please make sure it is accessible at /vuetorrent/public')
})

app.get('/ping', async (req, res) => {
res.send('pong')
const server = app.listen(PORT, async () => {
console.log('Checking for updates...')
console.log(await checkForUpdate())
console.log(`Server is running on port ${ PORT }`)
})

async function handle_signal(signal) {
async function stopServer(signal) {
console.log(`Received ${ signal } signal. Gracefully shutting down...`)
process.exit(0)
server.close()
}

process.on('SIGTERM', handle_signal)
process.on('SIGINT', handle_signal)

app.listen(PORT, () => {
console.log(`Server is running on port ${ PORT }`)
})
process.on('SIGTERM', stopServer)
process.on('SIGINT', stopServer)
Loading

0 comments on commit f26dffe

Please sign in to comment.