-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experimental): abstract data layer
Defined a database layer Added an implementation using mongoose Refactored the express routes to take an implementation Added a mockable implementation Refactored the tests to use the mockable implementation Added tests for the get by uuid route
- Loading branch information
1 parent
3f355df
commit 6c4553c
Showing
14 changed files
with
398 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
import express from 'express'; | ||
import { logger } from '@/logger'; | ||
import apiRouter from '@/routes/api'; | ||
import createApiRouter from '@/routes/api'; | ||
import pinoHTTP from 'pino-http'; | ||
import bodyParser from 'body-parser'; | ||
import { rateLimit } from 'express-rate-limit'; | ||
import helmet from 'helmet'; | ||
import { LicenseDataService } from './services/data'; | ||
// import lusca from 'lusca'; | ||
|
||
// helmet and lusca comparison | ||
// https://github.com/krakenjs/lusca/issues/42#issuecomment-65093906 | ||
// TODO: integrate lusca once added sessions/auth | ||
|
||
const app = express(); | ||
const createApp = (lds: LicenseDataService) => { | ||
const app = express(); | ||
|
||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, | ||
limit: 100, | ||
standardHeaders: 'draft-7', | ||
legacyHeaders: false, | ||
// in memory store | ||
}); | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, | ||
limit: 100, | ||
standardHeaders: 'draft-7', | ||
legacyHeaders: false, | ||
// in memory store | ||
}); | ||
|
||
app.use(helmet()); | ||
app.use(limiter); | ||
app.use(bodyParser.json()); | ||
app.use( | ||
pinoHTTP({ | ||
logger, | ||
autoLogging: process.env.NODE_ENV === 'development', | ||
// overrides core logger redaction | ||
// please update in logger.ts | ||
// redact: [], | ||
}), | ||
); | ||
app.use(helmet()); | ||
app.use(limiter); | ||
app.use(bodyParser.json()); | ||
app.use( | ||
pinoHTTP({ | ||
logger, | ||
autoLogging: process.env.NODE_ENV === 'development', | ||
// overrides core logger redaction | ||
// please update in logger.ts | ||
// redact: [], | ||
}), | ||
); | ||
|
||
app.use('/api', apiRouter); | ||
|
||
export { app }; | ||
app.use('/api', createApiRouter(lds)); | ||
return app; | ||
}; | ||
export { createApp }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Mongoose, Model } from 'mongoose'; | ||
import { licenseSchema, type LicenseSchema } from './schemas/license/license'; | ||
|
||
export class Database { | ||
mongoose: Mongoose; | ||
License: Model<LicenseSchema>; | ||
constructor(mongoose: Mongoose) { | ||
this.mongoose = mongoose; | ||
this.License = mongoose.model<LicenseSchema>('License', licenseSchema); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import express from 'express'; | ||
import v0Router from './v0'; | ||
const router = express.Router(); | ||
import createV0Router from './v0'; | ||
import { LicenseDataService } from '@/services/data'; | ||
|
||
router.use('/v0', v0Router); | ||
const createRouter = (lds: LicenseDataService) => { | ||
const router = express.Router(); | ||
|
||
export default router; | ||
router.use('/v0', createV0Router(lds)); | ||
return router; | ||
}; | ||
|
||
export default createRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import express from 'express'; | ||
import licensesRouter from './licenses'; | ||
const router = express.Router(); | ||
import createLicensesRouter from './licenses'; | ||
import { LicenseDataService } from '@/services/data'; | ||
|
||
router.use('/licenses', licensesRouter); | ||
const createRouter = (lds: LicenseDataService) => { | ||
const router = express.Router(); | ||
|
||
export default router; | ||
router.use('/licenses', createLicensesRouter(lds)); | ||
return router; | ||
}; | ||
|
||
export default createRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.