Skip to content

Instantly share code, notes, and snippets.

@micahwalter

micahwalter/emoji.js

Created Oct 19, 2018
Embed
What would you like to do?
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