forked from maxis1718/gulis-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (49 loc) · 1.33 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* jshint node: true, devel: true */
'use strict';
var app = require('express')();
var bodyParser = require('body-parser');
var router = require('./lib/beauty-router');
var ElasticSearch = require('./lib/elasticsearch');
var config = require('config');
var db = config.get('db.elasticsearch');
// set db uri
ElasticSearch.source.setUri(db.uri);
app.set('port', process.env.PORT || 5000);
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
// Routes
/*
* entry for search
* query
* keyword: 長腿
* push: 46
* limit: 2
*/
app.get('/beauty/search', router.search);
/*
* entry for handling user feedback
* body
* like: true/false
* imgId: target image id
* userId: user id
*/
app.post('/beauty/feedback', router.feedback);
/*
* entry for logging
* body
* user: {string} user id or user name
* raw: {string} user's raw input
* (optional) meta: {object} containing user_id, user_ip
*/
app.post('/beauty/logging', router.logging);
/*
* entry for getting trending
* query
* (optional) userId
*/
app.get('/beauty/trending', router.trending);
// start server after connecting to mongodb
app.listen(app.get('port'), function() {
console.log('[node] app is running on port', app.get('port'));
});
module.exports = app;