Browse Source

add index api

Aneurin Barker Snook 1 year ago
parent
commit
54778eb435
2 changed files with 15 additions and 2 deletions
  1. 13 1
      src/http.ts
  2. 2 1
      tsconfig.json

+ 13 - 1
src/http.ts

@@ -2,10 +2,11 @@ import * as account from './account/api'
 import * as herd from './herd/api'
 import * as task from './task/api'
 import type { Context } from './types'
-import type { ErrorRequestHandler } from 'express'
 import cors from 'cors'
 import express from 'express'
 import { http } from '@edge/misc-utils'
+import { version } from '../package.json'
+import type { ErrorRequestHandler, RequestHandler } from 'express'
 
 /** Create an Express application. */
 function createExpress(ctx: Context) {
@@ -17,6 +18,9 @@ function createExpress(ctx: Context) {
 
   const prefix = ctx.config.api.prefix
 
+  // Misc APIs
+  app.get(prefix, index)
+
   // Account APIs
   app.post(`${prefix}/account`, account.createAccount(ctx))
   app.get(`${prefix}/account/:id?`, account.getAccount())
@@ -63,4 +67,12 @@ function createExpress(ctx: Context) {
   return app
 }
 
+const index: RequestHandler = (req, res, next) => {
+  res.send({
+    product: 'Herda Server',
+    version,
+  })
+  next()
+}
+
 export default createExpress

+ 2 - 1
tsconfig.json

@@ -8,6 +8,7 @@
     "skipLibCheck": true,
     "declaration": false,
     "removeComments": false,
+    "resolveJsonModule": true,
 
     "noUnusedLocals": true,
     "noUnusedParameters": false,
@@ -15,5 +16,5 @@
 
     "outDir": "out"
   },
-  "include": ["src"]
+  "include": ["src", "package.json"]
 }