Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 53 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
on:
push:
branches:
- '**'
- '**'
tags-ignore:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches:
- master
Expand All @@ -17,29 +17,54 @@ jobs:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: checkout
uses: actions/checkout@v1
- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v1
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ matrix.platform }}-node-${{ matrix.node }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ matrix.platform }}-node-${{ matrix.node }}
- name: install deps
run: npm ci
- name: run lint
run: npm run lint
- name: run format
run: npm run format
- name: run tests
run: npm run test
- name: build
run: npm run build
- name: setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: checkout
uses: actions/checkout@v1
- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v1
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ matrix.platform }}-node-${{ matrix.node }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ matrix.platform }}-node-${{ matrix.node }}
- name: install deps
run: npm ci
- name: run lint
run: npm run lint
- name: run format
run: npm run format
- name: run tests
run: npm run test
- name: build
run: npm run build
push_to_registry:
if: github.ref == 'refs/heads/master'
name: login, build and push docker image to docker hub
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: gqleditor/ts-api-faker
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
11 changes: 2 additions & 9 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { run } from 'micro';
import { Server } from 'http';
import handler from '../src';
import { srv } from '../src';
import { request, IncomingHttpHeaders } from 'http';
import { gzip, gunzip } from 'zlib';

describe('test micro integration', () => {
const server = new Server((req, res) => run(req, res, handler));

beforeAll((done) => {
server.listen(3000, () => done());
});
afterAll((done) => {
server.close(() => done());
srv.close(() => done());
});
const makeRequest = ({
body,
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { buffer, createError } from 'micro';
import { ServerResponse, IncomingMessage, Server } from 'http';
import { gunzip } from 'zlib';
import { gzip, header } from './util';
import { run } from 'micro'
import { run } from 'micro';

async function getBody(req: IncomingMessage): Promise<unknown> {
let data = '';
Expand Down Expand Up @@ -35,7 +35,7 @@ async function getBody(req: IncomingMessage): Promise<unknown> {
}
}

const serveFakeData = async (req: IncomingMessage, res: ServerResponse): Promise<unknown> => {
export const serveFakeData = async (req: IncomingMessage, res: ServerResponse): Promise<unknown> => {
if (((req || {}).method || '').toUpperCase() === 'OPTIONS') {
res.setHeader('Access-Control-Max-Age', `${3600 * 24}`);
res.setHeader('Access-Control-Allow-Origin', '*');
Expand Down Expand Up @@ -67,16 +67,16 @@ const serveFakeData = async (req: IncomingMessage, res: ServerResponse): Promise
return gzipResponse ? gzip(body) : body;
};

const srv = new Server((req, res) => run(req, res, serveFakeData));
export const srv = new Server((req, res) => run(req, res, serveFakeData));
srv.listen(3000, () => {
console.log('Now listenning on port 3000');
});

const finish = () => {
export const finish = () => {
console.log('Gracefully shutting down');
srv.close(() => {
console.log('Exiting ....');
});
}
process.on('SIGINT', finish)
process.on('SIGTERM', finish)
};
process.on('SIGINT', finish);
process.on('SIGTERM', finish);