feat: added sample get endpoint
This commit is contained in:
parent
85cf0e6d13
commit
b9b873a915
|
@ -1,14 +1,15 @@
|
|||
import http from 'http'
|
||||
|
||||
import express, { Application } from 'express'
|
||||
import initDebug from 'debug'
|
||||
|
||||
import { registerMiddlewares } from './middlewares'
|
||||
|
||||
import indexRouter from './routes'
|
||||
import usersRouter from './routes/users'
|
||||
|
||||
import { normalizePort } from './helpers/port'
|
||||
import { getErrorCb, getListeningCb } from './helpers/server-callbacks'
|
||||
import { registerMiddlewares } from './middlewares'
|
||||
import { registerApis } from './routes/api/register'
|
||||
|
||||
const PORT = normalizePort(process.env.PORT || '6595')
|
||||
|
||||
|
@ -23,6 +24,9 @@ registerMiddlewares(app)
|
|||
app.use('/', indexRouter)
|
||||
app.use('/users', usersRouter)
|
||||
|
||||
/* === APIs === */
|
||||
registerApis(app)
|
||||
|
||||
/* === Config === */
|
||||
app.set('port', PORT)
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
import sample from './sample'
|
||||
|
||||
export default [sample]
|
|
@ -0,0 +1,11 @@
|
|||
import { ApiHandler } from '../../../types'
|
||||
|
||||
const path: ApiHandler['path'] = '/sample'
|
||||
|
||||
const handler: ApiHandler['handler'] = (_, res) => {
|
||||
res.send('Mandi')
|
||||
}
|
||||
|
||||
const apiHandler: ApiHandler = { path, handler }
|
||||
|
||||
export default apiHandler
|
|
@ -0,0 +1,10 @@
|
|||
import { Application } from 'express'
|
||||
import getEndpoints from './get'
|
||||
|
||||
const prependApiPath = (path:string) => `/api${path}`
|
||||
|
||||
export function registerApis (app: Application) {
|
||||
getEndpoints.forEach((getApi) => {
|
||||
app.get(prependApiPath(getApi.path), getApi.handler)
|
||||
})
|
||||
}
|
|
@ -1 +1,8 @@
|
|||
import { RequestHandler } from 'express'
|
||||
|
||||
export type Port = number | string | boolean
|
||||
|
||||
export interface ApiHandler {
|
||||
path: string
|
||||
handler: RequestHandler
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue