mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Fixes to urls, allowedUrls, and env variables
This commit is contained in:
@@ -9,6 +9,7 @@ import regionRouter from './routes/region'
|
||||
import personRouter from './routes/person'
|
||||
import projectRouter from './routes/project'
|
||||
import speciesRouter from './routes/species'
|
||||
import localitySpeciesRouter from './routes/localitySpecies'
|
||||
import refreshTokenRouter from './routes/refresh'
|
||||
import timeBoundRouter from './routes/timeBound'
|
||||
import timeUnitRouter from './routes/timeUnit'
|
||||
@@ -43,6 +44,7 @@ app.use(userExtractor)
|
||||
|
||||
app.use('/user', userRouter)
|
||||
app.use('/locality', localityRouter)
|
||||
app.use('/locality-species', localitySpeciesRouter)
|
||||
app.use('/species', speciesRouter)
|
||||
app.use('/reference', referenceRouter)
|
||||
app.use('/time-unit', timeUnitRouter)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Middleware } from '../types'
|
||||
|
||||
/* Disables all write routes except the ones excluded by "allowedRoutes" */
|
||||
export const blockWriteRequests: Middleware = (req, res, next) => {
|
||||
const allowedRoutes = ['/user/login']
|
||||
const allowedRoutes = ['/user/login', '/locality-species/', '/refreshToken']
|
||||
const writeMethods = ['POST', 'PUT', 'PATCH', 'DELETE']
|
||||
if (writeMethods.includes(req.method) && !allowedRoutes.includes(req.path)) {
|
||||
return res.status(403).send()
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import { Request, Router } from 'express'
|
||||
import {
|
||||
getAllLocalities,
|
||||
getLocalityDetails,
|
||||
getLocalitySpeciesList,
|
||||
validateEntireLocality,
|
||||
} from '../services/locality'
|
||||
import { getAllLocalities, getLocalityDetails, validateEntireLocality } from '../services/locality'
|
||||
import { fixBigInt } from '../utils/common'
|
||||
import { EditDataType, LocalityDetailsType } from '../../../frontend/src/backendTypes'
|
||||
import { write } from '../services/write/write'
|
||||
@@ -18,14 +13,6 @@ router.get('/all', async (req, res) => {
|
||||
return res.status(200).send(fixBigInt(localities))
|
||||
})
|
||||
|
||||
router.post('/localitySpecies', async (req: Request<object, object, { lids: number[] }>, res) => {
|
||||
const user = req.user
|
||||
const lids = req.body.lids
|
||||
if (!lids) return res.status(400).send({ message: 'Missing lids' })
|
||||
const localitySpeciesList = await getLocalitySpeciesList(lids, user)
|
||||
return res.status(200).json(localitySpeciesList)
|
||||
})
|
||||
|
||||
router.get('/:id', async (req, res) => {
|
||||
const id = parseInt(req.params.id)
|
||||
const locality = await getLocalityDetails(id, req.user)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Request, Router } from 'express'
|
||||
import { getLocalitySpeciesList } from '../services/locality'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.post('/', async (req: Request<object, object, { lids: number[] }>, res) => {
|
||||
const user = req.user
|
||||
const lids = req.body.lids
|
||||
if (!lids) return res.status(400).send({ message: 'Missing lids' })
|
||||
const localitySpeciesList = await getLocalitySpeciesList(lids, user)
|
||||
return res.status(200).json(localitySpeciesList)
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import { Router } from 'express'
|
||||
import { sign } from 'jsonwebtoken'
|
||||
import { SECRET, LOGIN_VALID_SECONDS, USER_CREATION_SECRET } from '../utils/config'
|
||||
import { SECRET, LOGIN_VALID_SECONDS } from '../utils/config'
|
||||
import * as bcrypt from 'bcrypt'
|
||||
import { nowDb } from '../utils/db'
|
||||
import { getRole } from '../middlewares/authenticator'
|
||||
@@ -68,9 +68,7 @@ const createPasswordHash = async (password: string) => {
|
||||
}
|
||||
|
||||
router.post('/create', requireOneOf([Role.Admin]), async (req, res) => {
|
||||
const { username, password, secret } = req.body
|
||||
|
||||
if (!secret || secret !== USER_CREATION_SECRET) throw Error('Wrong user creation secret')
|
||||
const { username, password } = req.body
|
||||
|
||||
const passwordHash = await createPasswordHash(password as string)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ export const PORT = process.env.NOWDB_BACKEND_PORT as unknown as number
|
||||
export const LOGIN_VALID_SECONDS = parseInt(process.env.LOGIN_VALID_MINUTES as string) * 60
|
||||
export const GRACE_PERIOD_SECONDS = parseInt(process.env.GRACE_PERIOD_MINUTES || '60') * 60
|
||||
|
||||
export const MARIADB_USER = process.env.MARIADB_USER as string
|
||||
export const MARIADB_PORT = parseInt(process.env.MARIADB_PORT as string)
|
||||
export const USER_CREATION_SECRET = process.env.USER_CREATION_SECRET as string
|
||||
|
||||
@@ -40,6 +41,7 @@ const requiredEnvs = {
|
||||
LOG_DB_NAME,
|
||||
COORDINATOR,
|
||||
RUNNING_ENV,
|
||||
MARIADB_USER,
|
||||
}
|
||||
|
||||
const missingEnvs = Object.entries(requiredEnvs).filter(([, value]) => value === undefined)
|
||||
|
||||
@@ -3,7 +3,7 @@ import { logger } from './logger'
|
||||
import { PrismaClient as NowClient } from '../../prisma/generated/now_test_client'
|
||||
import { PrismaClient as LogClient } from '../../prisma/generated/now_log_test_client'
|
||||
import mariadb from 'mariadb'
|
||||
import { MARIADB_HOST, MARIADB_PASSWORD, DB_CONNECTION_LIMIT } from './config'
|
||||
import { MARIADB_HOST, MARIADB_PASSWORD, DB_CONNECTION_LIMIT, MARIADB_USER } from './config'
|
||||
|
||||
export const logDb = new LogClient()
|
||||
export const nowDb = new NowClient()
|
||||
@@ -11,7 +11,7 @@ export const nowDb = new NowClient()
|
||||
export const pool = mariadb.createPool({
|
||||
host: MARIADB_HOST,
|
||||
password: MARIADB_PASSWORD,
|
||||
user: 'now_test',
|
||||
user: MARIADB_USER,
|
||||
connectionLimit: parseInt(DB_CONNECTION_LIMIT),
|
||||
})
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ const localitiesApi = api.injectEndpoints({
|
||||
}),
|
||||
getLocalitySpeciesList: builder.mutation<unknown[], number[]>({
|
||||
query: (lids: number[]) => ({
|
||||
url: `/locality/localitySpecies/`,
|
||||
url: `/locality-species/`,
|
||||
body: { lids },
|
||||
method: 'POST',
|
||||
}),
|
||||
|
||||
@@ -8,7 +8,7 @@ export enum Role {
|
||||
ReadOnly = 7,
|
||||
}
|
||||
|
||||
import { LocalityDetailsType } from '@/backendTypes'
|
||||
import { LocalityDetailsType } from '../src/backendTypes'
|
||||
|
||||
export const calculateMeanHypsodonty = (locality: LocalityDetailsType) => {
|
||||
// Mean hypsodonty calculation has been made based on html/include/database.php line 2567 onwards
|
||||
|
||||
Reference in New Issue
Block a user