Skip to content

Instantly share code, notes, and snippets.

@micahwalter
Created October 19, 2018 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micahwalter/8c4c2fca2f12ab85157736b2d751229f to your computer and use it in GitHub Desktop.
Save micahwalter/8c4c2fca2f12ab85157736b2d751229f to your computer and use it in GitHub Desktop.
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