
Product
Reachability for Ruby Now in Beta
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.
@titicaca/ntk-koa-helpers
Advanced tools
@titicaca/triple-koa-helpers๋ชจ๋๋ณ ๋ฌธ์๋ ๋ค์์ ์ฐธ์กฐํด์ฃผ์ญ์์ค:
๋จผ์ ์๋์ ๊ฐ์ด ์๋ฒ, ๊ทธ๋ฆฌ๊ณ ์ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์ฑํด์ค๋๋ค.
src/index.ts
import * as Sentry from '@sentry/node'
import { Context } from 'koa'
import {
responseParserMiddleware,
catchAppErrorsMiddleware,
} from '@titicaca/ntk-koa-helpers'
import { SENTRY_DSN, SENTRY_ENV } from './config'
import { createApp } from './app'
import { logger } from './logger'
const PORT = parseInt(process.env.PORT || '3000', 10)
if (SENTRY_DSN) {
Sentry.init({ dsn: SENTRY_DSN, environment: SENTRY_ENV })
}
function main() {
const koaApp = createApp()
if (SENTRY_DSN) {
koaApp.on(
'error',
(
err,
ctx: Context & {
request: Sentry.PolymorphicRequest
},
) => {
Sentry.withScope((scope) => {
scope.addEventProcessor((event) =>
Sentry.addRequestDataToEvent(event, ctx.request),
)
Sentry.captureException(err)
})
},
)
}
const server = koaApp.listen(PORT, () => {
// eslint-disable-next-line no-console
logger.info(`Koa server listening on ${PORT}.`)
})
server.keepAliveTimeout = 90 * 1000
}
// NOTE: ์๋ฌ ์ผํธ๋ฆฌ ํ
์ถ๊ฐ
catchUnhandledRejection(logger, (err) => {
if (SENTRY_DSN) {
Sentry.captureException(err)
}
})
main()
src/app.ts
import Koa from 'koa'
import Router from 'koa-router'
import bodyParser from 'koa-bodyparser'
import {
responseParserMiddleware,
catchAppErrorsMiddleware,
} from '@titicaca/ntk-koa-helpers'
import tripleUserKoaMiddleware from '@titicaca/triple-user-auth-middleware'
import { httpLogger } from '@titicaca/ntk-logger'
import { logger } from './logger'
import * as poi from './poi'
const bodyParserMiddleware: Koa.Middleware = bodyParser({
detectJSON: ({ request: { type } }) => /\bjson$/.test(type),
enableTypes: ['json'],
jsonLimit: '1mb', // ๊ธฐ๋ณธ๊ฐ์ด 1mb ์
๋๋ค. ๋ง์ฝ ๋ ํฐ json body๋ฅผ ๋ฐ์์ผ ํ ํ์๊ฐ ์๋ค๋ฉด ์ฌ๊ธฐ๋ฅผ ์์ ํ์ธ์.
})
export function createApp() {
return new Koa()
.use(
catchAppErrorsMiddleware(logger, () => {
console.log('CALLED AFTER HANDLING APP ERROR')
}),
) //์๋ฌ ํธ๋ค๋ฌ ๋ฏธ๋ค์จ์ด ๋ก๊ฑฐ ์ฃผ์
๋ฐ ํ
(ํ์ํ๋ค๋ฉด) ์ถ๊ฐ
.use(bodyParserMiddleware)
.use(tripleUserKoaMiddleware)
.use()
.use(httpLogger(logger))
.use(responseParserMiddleware) // ๊ผญ ๋ฏธ๋ค์จ์ด์ ๋ง์ง๋ง ์์๋ก ์ค์นํ์
์ผ ํฉ๋๋ค.
.use(
new Router()
.get('/health', (context) => {
context.status = 200
})
.routes(),
)
.use(routes())
}
function routes() {
const router = new Router()
router.use('/pois', poi.routes())
return router.routes()
}
์๋๋ agenda ์ถ๊ฐ ์์์ ๋๋ค. (์ฐธ์กฐ: ์์ค์ฝ๋)
src/index.ts
async function main() {
await initAgenda()
const koaApp = createApp()
...
}
src/agenda.ts
import { Agenda } from 'agenda'
import { defineJobs } from 'path/to/controller'
import { db } from './mongodb-adapter'
import { logger } from './logger'
export const agendaClient = new Agenda({
mongo: db,
defaultLockLifetime: 1000 * 60 * 60 * 3,
defaultConcurrency: 1,
defaultLockLimit: 50,
})
export async function initAgenda() {
defineJobs()
agendaClient.on('fail', async (err: unknown, job: Job) => {
const normalizedError = AppError.of({
code: "ASYNCHRONOUS_ERROR",
message: `Job id: ${job._id}๊ฐ ์คํจํ์ต๋๋ค.`
context: {
error,
job,
}
})
logger.error(normalizedError)
//retry logic ๋ฑ์ ์คํ
await handleJobFailure(job)
})
})
try {
await agendaClient.start()
} catch (err) {
console.error('์ด์ ๋ค ํด๋ผ์ด์ธํธ๋ฅผ ์์ํ๋๋ฐ์ ์คํจํ์ต๋๋ค:', err)
}
}
const tripleHttpErrors = require('@titicaca/triple-http-errors');
// TODO: DEMONSTRATE API
FAQs
> TODO: description
We found that @titicaca/ntk-koa-helpers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.ย It has 57 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.

Research
/Security News
Malicious npm packages use Adspect cloaking and fake CAPTCHAs to fingerprint visitors and redirect victims to crypto-themed scam sites.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Hereโs whatโs actually happening.