44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const express = require('express')
|
|
const app = express()
|
|
const request = require('request');
|
|
|
|
var Setting = {
|
|
appkey: 'c3954f8fddc58db4aabdbf05918afcff',
|
|
baseUrl: 'http://apis.juhe.cn/cook/'
|
|
}
|
|
|
|
app.all("*",function (req,res,next) {
|
|
res.header("Access-Control-Allow-Origin","*");
|
|
res.header("Access-Control-Allow-Headers", "X-Requested-With");
|
|
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
|
|
res.header("Content-Type", "application/json;charset=utf-8");
|
|
next();
|
|
});
|
|
|
|
app.get('/category', (req, res) => {
|
|
request(`${Setting.baseUrl}category?key=${Setting.appkey}`, function (error, response, body) {
|
|
res.json(JSON.parse(body))
|
|
});
|
|
});
|
|
|
|
app.get('/query', (req, res) => {
|
|
var menu = req.query.menu;
|
|
|
|
request(`${Setting.baseUrl}query?key=${Setting.appkey}&menu=${encodeURI(menu)}&rn=30&pn=3`, function (error, response, body) {
|
|
res.json(JSON.parse(body))
|
|
});
|
|
});
|
|
|
|
app.get('/index', (req, res) => {
|
|
var cid = req.query.cid,
|
|
pn = req.query.pn;
|
|
|
|
request(`${Setting.baseUrl}index?key=${Setting.appkey}&cid=${cid}&rn=30&pn=${pn}`, function (error, response, body) {
|
|
res.json(JSON.parse(body))
|
|
});
|
|
});
|
|
|
|
|
|
app.listen(3000, function(){
|
|
console.log('Example app listening on port 3000!')
|
|
}) |