Skip to content
Snippets Groups Projects
Select Git revision
  • 4719e952431332f4a095288cbb5d7f56232c6672
  • master default protected
  • 1.31
  • 4.27.0
  • 4.26.0
  • 4.25.5
  • 4.25.4
  • 4.25.3
  • 4.25.2
  • 4.25.1
  • 4.25.0
  • 4.24.3
  • 4.24.2
  • 4.24.1
  • 4.24.0
  • 4.23.6
  • 4.23.5
  • 4.23.4
  • 4.23.3
  • 4.23.2
  • 4.23.1
  • 4.23.0
  • 4.22.3
23 results

Monster_Constraints.html

Blame
  • issue-251.js 1.55 KiB
    const json =
        `[
                    {
                        "id": 2000,
                        "name": "Autobahn"
                    },
                    {
                        "id": 2001,
                        "name": "Bus"
                    },
                    {
                        "id": 2002,
                        "name": "Autobus"
                    },
                    {
                        "id": 2003,
                        "name": "Fahrrad"
                    },
                    {
                        "id": 2004,
                        "name": "Tram"
                    },
                    {
                        "id": 2005,
                        "name": "Flugzeug"
                    }
                ]`;
    
    
    
    // check if JSON is valid
    JSON.parse(json)
    
    const requestDelay = 10
    
    export default [
        {
            url: '/issue-251.json',
            method: 'get',
            rawResponse: async (req, res) => {
                res.setHeader('Content-Type', 'application/json')
                res.statusCode = 200
                
                const url= new URL(req.url, `http://${req.headers.host}`)
                const q = Object.fromEntries(url.searchParams)
                
                if (q && q.q) {
                    const query = q.q.toLowerCase()
                    const filtered = JSON.parse(json).filter(item => item.name.toLowerCase().includes(query))
                    setTimeout(function() {
                        res.end(JSON.stringify(filtered))
                    }, requestDelay);
                    return
                }
                
                setTimeout(function() {
                    res.end(json)
                }, requestDelay);
    
            },
        }
    
    ];