Created
February 15, 2017 16:24
-
-
Save danjohnson95/aacfe737e99457e649203aff8e6ad758 to your computer and use it in GitHub Desktop.
Node search engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just add this file in the root of cops, and then in the cops-socket.js file, put this somewhere near the top: