Skip to content

Commit

Permalink
Create cors translator | Create settings for deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
andrelmlins committed Jun 21, 2020
1 parent 26779e3 commit 842da5a
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 7 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install --frozen-lockfile
- run: yarn build
31 changes: 31 additions & 0 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- run: yarn install --frozen-lockfile
- run: yarn build

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: yarn install --frozen-lockfile
- run: yarn build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 RecifeJs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<img alt="RecifeJs" width="400" src="https://raw.githubusercontent.com/recifejs/recife/master/logo.png" />

[![npm version](https://img.shields.io/npm/v/recife-express?style=flat-square&logo=npm)](https://www.npmjs.com/package/recife-express) [![License: MIT](https://img.shields.io/github/license/recifejs/recife-express?style=flat-square)](https://github.com/recifejs/recife-express/blob/master/LICENSE) [![Node.js CI](https://img.shields.io/github/workflow/status/recifejs/recife-express/Node.js%20CI?style=flat-square&logo=github)](https://github.com/recifejs/recife-express/workflows/Node.js%20CI)

Recife Express is a integration of recifejs with [express](https://expressjs.com/). For more details access the [documentation](https://recifejs.org/).

## Install

```bash
npm install recife-express
# or
yarn add recife-express
```

## Using in RecifeJs project

Open file `config/app.ts` and insert the value `express` in the property `httpFramework`:

```ts
import { AppConfig } from 'recife';

export const config: AppConfig = {
// ...
httpFramework: 'express'
// ...
};
```

## License

Recife Express is open source software [licensed as MIT](https://github.com/recifejs/recife-express/blob/master/LICENSE).
23 changes: 21 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
{
"name": "recife-express",
"version": "1.0.0",
"main": "index.js",
"description": "Recife Express is a integration of recifejs with express",
"version": "0.1.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"repository": "https://github.com/recifejs/recife-express",
"homepage": "https://recifejs.org/",
"files": [
"dist",
"README.md"
],
"scripts": {
"build": "tsc -p ."
},
"bugs": {
"url": "https://github.com/recifejs/recife-express/issues"
},
"keywords": [
"recife",
"express",
"integration",
"framework",
"graphql",
"nodejs"
],
"dependencies": {
"apollo-server-express": "^2.15.0"
},
Expand Down
26 changes: 21 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express, { Express } from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import cors, { CorsOptions } from 'cors';
import bodyParser, { Options } from 'body-parser';
import { ApolloServer, IResolvers } from 'apollo-server-express';
import { ApolloServerBase, Context, Config } from 'apollo-server-core';
import { DocumentNode } from 'graphql';
Expand All @@ -24,17 +24,33 @@ class RecifeExpress {
constructor(bodyParserConfig: any, corsConfig: any, homepage: string) {
this.app = express();

this.app.use(bodyParser(bodyParserConfig));
// this.app.use(bodyParser(this.bodyParserTranslator(bodyParserConfig)));

if (cors) {
this.app.use(cors(corsConfig));
if (corsConfig && corsConfig.enabled) {
this.app.use(cors(this.corsTranslator(corsConfig)));
}

this.app.get('/', (_req, res) => {
res.send(homepage);
});
}

private corsTranslator(corsConfig: any): CorsOptions {
return {
origin: corsConfig.origin,
methods: corsConfig.allowMethods,
allowedHeaders: corsConfig.allowHeaders,
exposedHeaders: corsConfig.exposeHeaders,
credentials: corsConfig.credentials,
maxAge: corsConfig.maxAge
};
}

private bodyParserTranslator(bodyParserConfig: any): Options {
// to do
return bodyParserConfig;
}

createApolloServer({
typeDefs,
resolvers,
Expand Down

0 comments on commit 842da5a

Please sign in to comment.