Skip to content

A strange hack using zeit/micro and abusing pugjs.

Notifications You must be signed in to change notification settings

andrewsosa/micro-pugjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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)

About

A strange hack using zeit/micro and abusing pugjs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published