Skip to content

Instantly share code, notes, and snippets.

@viktor-evdokimov
Created October 30, 2017 06:21
Show Gist options
  • Save viktor-evdokimov/ab99efeff8a4c12a91a2ab9dd927fd8b to your computer and use it in GitHub Desktop.
Save viktor-evdokimov/ab99efeff8a4c12a91a2ab9dd927fd8b to your computer and use it in GitHub Desktop.
Node.js and micro simple web service for running in K8S with draft
const http = require('http')
const { run, send, json } = require('micro')
const PORT = process.env.PORT || 8080
const response = "Hi from MICROservice on K8S draft"
const microHttp = fn => http.createServer((req, res) => run(req, res, fn))
const server = microHttp(async (req, res) => {
const js = await json(req);
const statusCode = 200;
const data = { ...js, response };
send(res, statusCode, data);
})
server.listen(PORT)
console.log(`Listening on https://localhost:${PORT}`)
{
"name": "node",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "node ."
},
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"micro": "^9.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment