1
restaurant-search/server/server.js
2014-10-02 16:41:47 +09:00

51 lines
1.1 KiB
JavaScript
Executable File

#!/usr/bin/env node
'use strict';
var _ = require('underscore');
var express = require('express');
var path = require('path');
var search = require('./search.js');
function main() {
var app = express();
search.loadDb({
'host': 'localhost',
'user': 'hscd',
'database': 'hscd'
});
app.use('/get_keywords', function(req, res) {
search.getKeywords(function(keywords) {
res.json(_.keys(keywords).sort());
});
});
app.use('/add_keyword', function(req, res) {
search.addKeyword(req.query, function(results) {
res.json(results);
});
});
app.use('/remove_keyword', function(req, res) {
search.removeKeyword(req.query, function(results) {
res.json(results);
});
});
app.use('/search', function(req, res) {
search.execQuery(req.query, function(results) {
res.json(results);
});
});
app.use(express.static(path.join(__dirname, '../client')));
app.listen(3000);
}
if (require.main === module) {
main();
}