Skip to content

Instantly share code, notes, and snippets.

@danjohnson95
Created February 15, 2017 16:24
Show Gist options
  • Save danjohnson95/aacfe737e99457e649203aff8e6ad758 to your computer and use it in GitHub Desktop.
Save danjohnson95/aacfe737e99457e649203aff8e6ad758 to your computer and use it in GitHub Desktop.
Node search engine
var http = require('http');
module.exports = function(){
var server;
var port = 3050;
startServer = function(){
server = http.createServer(handleRequest);
server.listen(port);
};
checkForBlankRequest = function(req, res){
if(req.url.substr(0, 8) != "/search/" || req.url.substr(8) == "")
res.end('No search term specified');
};
handleRequest = function(req, res){
checkForBlankRequest(req, res);
var term = req.url.substr(8); // Assuming the uri is /search/{query}
// Do your mysql stuff here,
// when finished run this to return results.
results = {};
res.end(results);
};
startServer();
};
@danjohnson95
Copy link
Author

Just add this file in the root of cops, and then in the cops-socket.js file, put this somewhere near the top:

var search = require('./search.js')();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment