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.

Revisions

  1. viktor-evdokimov created this gist Oct 30, 2017.
    15 changes: 15 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    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}`)
    15 changes: 15 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    {
    "name": "node",
    "version": "1.0.0",
    "description": "",
    "scripts": {
    "start": "node ."
    },
    "main": "index.js",
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
    "micro": "^9.0.0"
    }
    }