Created
October 30, 2017 06:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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