Skip to content

Instantly share code, notes, and snippets.

@kuzunoha-ne
kuzunoha-ne / app.ts
Last active January 3, 2020 10:12
httpでBasicAuth
import http from 'http';
import { Buffer } from 'buffer';
const server = http.createServer();
server.on('request', (req:http.IncomingMessage, res:http.ServerResponse) => {
if(req.headers.authorization) { // req.headers.authorization = "Basic a3V6dW5vaGE6YWFh"
const encodedPass = req.headers.authorization.split(' ')[1]; // encodedPass = "a3V6dW5vaGE6YWFh"
const decodePass = Buffer.from(encodedPass, 'base64').toString('utf8'); // decodedPass = "kuzunoha:hogehoge"
const auth = {username:decodePass.split(':')[0], password:decodePass.split(':')[1]}; // auth = {username:kuzunoha, password:hogehoge}
name: Node CI
on: [push]
jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with: