1
0
Fork 0
mirror of https://github.com/betagouv/mon-entreprise synced 2025-02-13 08:25:01 +00:00
mon-entreprise/api/source/index.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
850 B
TypeScript
Raw Normal View History

2022-05-16 14:29:59 +02:00
import cors from '@koa/cors'
import Router from '@koa/router'
import Koa from 'koa'
import rules from 'modele-social'
import Engine from 'publicodes'
import { koaMiddleware as publicodesAPI } from 'publicodes-api'
2022-05-17 14:18:32 +02:00
// @ts-ignore
2022-05-16 14:29:59 +02:00
import openapi from './openapi.json'
import { docRoutes } from './route/doc.js'
2022-05-17 14:18:32 +02:00
import { openapiRoutes } from './route/openapi.js'
2022-05-16 14:29:59 +02:00
type State = Koa.DefaultState
type Context = Koa.DefaultContext
const app = new Koa<State, Context>()
const router = new Router<State, Context>()
app.use(cors())
2022-05-17 14:18:32 +02:00
const apiRoutes = publicodesAPI(() => new Engine(rules))
2022-05-16 14:29:59 +02:00
2022-05-17 14:18:32 +02:00
router.use('/v1', apiRoutes, docRoutes(), await openapiRoutes(openapi))
2022-05-16 14:29:59 +02:00
app.use(router.routes())
app.use(router.allowedMethods())
const port = 3004
app.listen(port, function () {
// eslint-disable-next-line no-console
console.log('listening on port:', port)
})