REST Service for POPCORN - ILIAS
alex
2025-05-26 be556d5982e743d0af7cbf63a619b77d23a13f2a
app.js
@@ -1,7 +1,9 @@
const fastify = require('fastify')({
   logger: true
})
const _ = require("lodash")
const db = require("./lib/db")
const settings = require("./settings")
/////////////////////////////////////////////////////////////////////////
@@ -19,16 +21,16 @@
})
fastify
   .get('/api/users', async function (req, res) {
   .get('/users', async function (req, res) {
      const {offset, limit} = req.query
      const users = await db.getUsers(offset, limit)
      return res.send(users)
   })
   .get("/api/users/count", async function (req, res) {
   .get("/users/count", async function (req, res) {
      const count = await db.getUserCount()
      return res.send(count)
   })
   .get("/api/user/login/:login", async function (req, res) {
   .get("/user/login/:login", async function (req, res) {
      const {login} = req.params
      const user = await db.getUserByLogin(login)
      if (user.length) {
@@ -38,11 +40,11 @@
         return res.code(404).send({status: "error", msg: "not found"})
      }
   })
   .get("/api/user/userid/:userid", async function (req, res) {
   .get("/user/userid/:userid", async function (req, res) {
      const {userid} = req.params
      const user = await db.getUserByUserId(userid)
      if (user.length) {
         return res.send(user[0])
      if (user) {
         return res.send(user)
      }
      else {
         return res.code(404).send({status: "error", msg: "not found"})
@@ -52,7 +54,7 @@
/////////////////////////////////////////////////////////////////////////
fastify.listen({port: 4101}, function (err, address) {
fastify.listen({port: settings.port}, function (err, address) {
   if (err) {
      fastify.log.error(err)
      process.exit(1)