-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
525 additions
and
256 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 |
---|---|---|
|
@@ -50,7 +50,7 @@ jobs: | |
npm run test-coverage-ci --workspaces --if-present | ||
- name: Upload test coverage report | ||
uses: codecov/[email protected].1 | ||
uses: codecov/[email protected].2 | ||
with: | ||
files: ./coverage/lcov.info | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -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
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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { z } from 'zod'; | ||
|
||
const envSchema = z.object({ | ||
PORT: z.coerce.number().default(3000), | ||
MONGO_URI: z.string(), | ||
}); | ||
const envSchema = z | ||
.object({ | ||
PORT: z.coerce.number().default(3000), | ||
MONGO_URI: z.string(), | ||
}) | ||
.required(); | ||
|
||
const { error, data: env } = envSchema.safeParse(process.env); | ||
if (error) { | ||
console.error(error); | ||
throw new Error('failed to validate'); | ||
} | ||
|
||
export default env; | ||
export default env as z.infer<typeof envSchema>; |
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; |
Oops, something went wrong.