Skip to content

Instantly share code, notes, and snippets.

@davidnuon
Created September 15, 2018 05:00
Show Gist options
  • Save davidnuon/4a4d5c6d8905ee89e075de729742480b to your computer and use it in GitHub Desktop.
Save davidnuon/4a4d5c6d8905ee89e075de729742480b to your computer and use it in GitHub Desktop.
A very serious gist
html
head
title= title
body
h1= 1970
p Music was awful.
html
head
title= title
body
h1= 1980
p NEVER GOING TO GIVE YOU UP.
const express = require('express')
const pug = require('pug')
const app = express()
// Takes `data` and plugs it into a `templateName.html` to render it
// It's pug template
function getMarkup(templateName, data) {
pug.compileFile('./' + templateName + '.html')(data)
}
// Route at /
app.get('/', (req, res) => {
// We check for two query parameters
// Year: ?year=...
let year = req.query.year || 1970;
// WordPress Query String: ?wp=...
let wp = req.query.wp;
// Log it out debug
console.log(year, wp, req, res);
// Get the markup from getMarkup
// then send it out in a response
res.send(getMarkup(year.toString() ,{}));
})
// Start that app at localhost:3000
app.listen(3000, () => console.log('Example app listening on port 3000!'))
{
"name": "fur_leo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"pug": "^2.0.3"
}
}
@davidnuon
Copy link
Author

davidnuon commented Sep 15, 2018

I put this in the public domain.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment