Skip to content

Commit

Permalink
creates api/client architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
tdjsnelling committed Dec 14, 2021
1 parent c806ad3 commit d8e111d
Show file tree
Hide file tree
Showing 27 changed files with 9,874 additions and 1,067 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**/node_modules
.cache
public
**/.cache
**/public
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
**/node_modules/
.env
.idea/
.env
client/.next
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions Dockerfile → api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:16-alpine
COPY . .
COPY .. .
RUN yarn
EXPOSE 44444
CMD yarn start
CMD yarn start
36 changes: 36 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@sqtracker/api",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "nodemon --exec babel-node src/index.js",
"start": "babel-node src/index.js"
},
"dependencies": {
"bcrypt": "^5.0.1",
"bencode": "^2.0.1",
"body-parser": "^1.19.0",
"chalk": "^4.1.1",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"http-proxy-middleware": "^2.0.1",
"jsonwebtoken": "^8.5.1",
"memoizee": "^0.4.15",
"mongoose": "^5.13.2",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"node-fetch": "^2.6.1",
"querystring": "^0.2.1"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/node": "^7.14.7",
"@babel/preset-env": "^7.14.7",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"nodemon": "^2.0.9",
"prettier": "^2.3.2"
}
}
File renamed without changes.
3 changes: 0 additions & 3 deletions src/controllers/user.js → api/src/controllers/user.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import bcrypt from 'bcrypt'
import jwt from 'jsonwebtoken'
import crypto from 'crypto'
import dotenv from 'dotenv'
import User from '../schema/user'
import Invite from '../schema/invite'

dotenv.config()

export const register = async (req, res) => {
if (
process.env.SQ_ALLOW_REGISTER !== 'open' &&
Expand Down
11 changes: 4 additions & 7 deletions src/index.js → api/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import express from 'express'
import morgan from 'morgan'
import chalk from 'chalk'
import dotenv from 'dotenv'
import bodyParser from 'body-parser'
import cors from 'cors'
import mongoose from 'mongoose'
Expand All @@ -23,25 +22,23 @@ import {
addComment,
} from './controllers/torrent'

dotenv.config()

const connectToDb = () => {
console.log('initiating db connection...')
console.log('[sq] initiating db connection...')
mongoose
.connect(process.env.SQ_MONGO_URL, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
})
.catch((e) => {
console.error(`error on initial db connection: ${e.message}`)
console.error(`[sq] error on initial db connection: ${e.message}`)
setTimeout(connectToDb, 5000)
})
}
connectToDb()

mongoose.connection.once('open', () => {
console.log('connected to mongodb successfully')
console.log('[sq] connected to mongodb successfully')
})

const app = express()
Expand Down Expand Up @@ -105,5 +102,5 @@ app.post('/torrent/:infoHash/comment', addComment)

const port = process.env.SQ_PORT || 44444
app.listen(port, () => {
console.log(`■ sqtracker running http://localhost:${port}`)
console.log(`[sq] ■ sqtracker running http://localhost:${port}`)
})
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import memoize from 'memoizee'
import querystring from 'querystring'
import dotenv from 'dotenv'
import User from '../schema/user'
import Torrent from '../schema/torrent'
import Progress from '../schema/progress'

dotenv.config()

const userLookup = async (userId) => {
return User.findOne({ uid: userId })
return User.findOne({ uid: userId }).lean()
}

const userLookupMemo = memoize(userLookup)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/routes/tracker.js → api/src/routes/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import bencode from 'bencode'
import dotenv from 'dotenv'

dotenv.config()
dotenv.config({ path: '../.env' })

export const userTrackerRoutes = createProxyMiddleware({
target: process.env.SQ_TRACKER_URL,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d8e111d

Please sign in to comment.