Created
October 19, 2018 18:43
-
-
Save micahwalter/8c4c2fca2f12ab85157736b2d751229f to your computer and use it in GitHub Desktop.
This file contains 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
const http = require('http'); | |
const path = require('path'); | |
const express = require('express'); | |
const translate = require('moji-translate'); | |
const app = express(); | |
app.use(express.static(path.join(__dirname, ''))); | |
app.set('views', './views') | |
app.set('view engine', 'pug') | |
app.get('/', function (req, res) { | |
const request = require('request') | |
const payload = { | |
query: `{ | |
objects(per_page: 200) { | |
id | |
title | |
} | |
}` | |
} | |
request( | |
{ | |
url: 'https://api.mplus.org.hk/graphql', | |
method: 'POST', | |
headers: { | |
'content-type': 'application/json', | |
Authorization: 'bearer <TOKEN>' | |
}, | |
json: payload | |
}, | |
(error, resp, body) => { | |
if (error) { | |
console.log(error) | |
} | |
if ('errors' in body) { | |
console.log(body.errors) | |
} | |
var html = ''; | |
body.data.objects.forEach(function(entry) { | |
t = translate.translate(entry.title) | |
html = html + ' / ' + t; | |
}); | |
//t = translate.translate(body.data.objects[4].title); | |
res.render('index', { title: "M+ Emoji", message: html }) | |
//console.log(body.data.object.title) | |
} | |
) | |
}); | |
http.createServer(app).listen(8080, function(){ | |
console.log('HTTP server listening on port 8080'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment