Skip to content

Instantly share code, notes, and snippets.

@Mobilpadde
Created May 14, 2017 23:37
Show Gist options
  • Save Mobilpadde/0026aaf59cadaa72072b22df5496085f to your computer and use it in GitHub Desktop.
Save Mobilpadde/0026aaf59cadaa72072b22df5496085f to your computer and use it in GitHub Desktop.
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.render("index.pug");
});
app.listen(3000);
// ...
module.exports = (uri => {
return new Promise((resolve, reject) => {
rp({
uri: uri,
followAllRedirects: true,
resolveWithFullResponse: true
}).then(res => {
resolve(res.request.uri.href);
}).catch(reject);
});
});
// ...
const express = require("express");
const check = require("./lib/checker.js");
const app = express();
// ...
// ...
const app = express();
app.set("view engine", "pug");
app.set("views", __dirname + "/views");
// ...
html
head
link(href="/main.css", rel="stylesheet")
body
#wrapper
input#url(type="text")
button#go Go Figure
h1#result
script(src="main.js")
*{
margin: 0;
padding: 0;
outline: none;
}
body{
font: 14px/1.1 sans-serif;
margin: 0 auto
}
#wrapper{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
#url, #go{
padding: 5px;
font-size: 2em;
border: none;
border-bottom: 2px solid #c9f1f1;
}
#go{
background: transparent;
border-radius: 2px 2px 0 2px;
transition: background 250ms ease-in;
}
#go:hover{
background: rgba(201, 241, 241, 0.35);
}
#result{
padding: 15px;
}
"use strict"
window.addEventListener("load", () => {
const url = document.getElementById("url");
const btn = document.getElementById("go");
const res = document.getElementById("result");
});
// ...
const res = document.getElementById("result");
btn.addEventListener("click", () => {
fetch("/check/" + url.value, {
method: "post"
})
.then(result => result.json())
.then(uri => res.innerText = uri);
});
// ...
// ...
app.get("/", (req, res) => {
res.render("index.pug");
});
app.post("/check/:url(*)", (req, res) => {
check(req.params.url).then(result => {
res.json(result);
});
});
// ...
const rp = require("request-promise");
const Promise = require("bluebird");
// ...
const Promise = require("bluebird");
module.exports = (uri => {
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment