Skip to content

Instantly share code, notes, and snippets.

/app.js Secret

Created February 26, 2016 14:48
Show Gist options
  • Save anonymous/ee5cfbbe436b860c8ecf to your computer and use it in GitHub Desktop.
Save anonymous/ee5cfbbe436b860c8ecf to your computer and use it in GitHub Desktop.
#2914 repro
var express = require('express');
var app = express();
var home = `
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.css">
<script>
$(document).ready(function () {
$('.ui.search').search({
apiSettings: {
url: 'search/{query}'
},
fields: {
title: 'title'
},
cache: false
});
$('input').val('');
});
</script>
</head>
<body>
<div class="ui container">
<h2>Enter a single letter. Before 5 seconds passes enter a second letter</h2>
<div class="ui search">
<input class="prompt" placeholder="..." type="text">
<div class="results"></div>
</div>
</div>
</body>
</html>
`
var results = {
"results": [{
"title": "wqertyuiopasdfghjklzxcvbnm",
"description": "one"
}, {
"title": "wqertyuiopasdfghjklzxcvbnm",
"description": "two"
}]
}
app.get('/', function(req, res) {
res.send(home);
});
app.get('/search/:query', function(req, res) {
var query = req.params.query;
if (query.length === 1) {
setTimeout(function() {
res.json(results);
}, 5000);
} else {
res.json(results);
}
});
app.listen(3000, function() {
console.log('Example app listening on port 3000!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment