Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrewsosa/micro-pugjs
A strange hack using zeit/micro and abusing pugjs.
https://github.com/andrewsosa/micro-pugjs
micro pug
Last synced: about 1 month ago
JSON representation
A strange hack using zeit/micro and abusing pugjs.
- Host: GitHub
- URL: https://github.com/andrewsosa/micro-pugjs
- Owner: andrewsosa
- Created: 2017-03-06T23:36:22.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-06T23:37:14.000Z (almost 8 years ago)
- Last Synced: 2024-11-05T22:44:09.992Z (3 months ago)
- Topics: micro, pug
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# `micro-pugjs`
A stupid demo of a stupid hack.
### `summary`
We're sending javascript code over in a single
`micro.send()` call.We achieve this by rendering the code we care about as
unbuffered code via pugjs. In our example, we also include
`jquery` to help give us bindings when the page loads.#### tl;dr:
Instead of including javascript files like a normal person,
I made this.### `so what?`
I don't know yet. Let me know if you figure it something out.### `index.js`
```javascript
const micro = require('micro')
const pug = require('pug')
const fs = require('fs')let locals = {};
locals.renderer = fs.readFileSync('./src/render.js')const server = micro(async (req, res) => {
var fn = pug.compileFile('./src/index.pug')
var html = fn(locals)
micro.send(res, 200, html)
})server.listen(3000)
```