Skip to content

Commit

Permalink
style: Prettify (automated)
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jul 1, 2020
1 parent 552c930 commit 03b8ea2
Show file tree
Hide file tree
Showing 10 changed files with 759 additions and 771 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Integration Tests

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

jobs:
build:
Expand All @@ -13,16 +13,16 @@ jobs:
node-version: [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 }}
- name: Install Dependencies
run: npm install && cd test/src && npm install && cd ../../
- name: Run Integration Tests
run: npm test
env:
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install && cd test/src && npm install && cd ../../
- name: Run Integration Tests
run: npm test
env:
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ orientation.
Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities
Expand Down
37 changes: 15 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<br/>

**Serverless Express** ⎯⎯⎯ This [Serverless Framework Component](https://github.com/serverless/components) enables you to take existing Express.js apps and deploy them onto cheap, auto-scaling, serverless infrastructure on AWS (specifically AWS HTTP API and AWS Lambda), easily. It's packed with production-ready features, like custom domains, SSL certificates, canary deployments, and costs an average of **$0.000003** per request.
**Serverless Express** ⎯⎯⎯ This [Serverless Framework Component](https://github.com/serverless/components) enables you to take existing Express.js apps and deploy them onto cheap, auto-scaling, serverless infrastructure on AWS (specifically AWS HTTP API and AWS Lambda), easily. It's packed with production-ready features, like custom domains, SSL certificates, canary deployments, and costs an average of **\$0.000003** per request.

<br/>

- [x] **Never Pay For Idle** - No HTTP requests, no cost. Averages ~$0.000003 per request.
- [x] **Never Pay For Idle** - No HTTP requests, no cost. Averages ~\$0.000003 per request.
- [x] **Zero Configuration** - All we need is your code, then just deploy (advanced config options are available).
- [x] **Fast Deployments** - Deploy changes to the cloud in seconds.
- [x] **Realtime Logging** - Rapidly develop on the cloud w/ real-time logs and errors in the CLI.
Expand Down Expand Up @@ -36,8 +36,8 @@ Get Started:

Extra:

* [**Architecture**](#Architecture)
* [**Guides**](#Guides)
- [**Architecture**](#Architecture)
- [**Guides**](#Guides)

&nbsp;

Expand Down Expand Up @@ -130,7 +130,7 @@ Once you've chosen your configuration, run `serverless deploy` again (or simply

<img src="/assets/dev-demo.gif" height="250" align="right">

Now that you've got your basic express app up and running, it's time to develop that into a real world application. Instead of having to run `serverless deploy` everytime you make changes you wanna test, run `serverless dev`, which allows the CLI to watch for changes in your source directory as you develop, and deploy instantly on save.
Now that you've got your basic express app up and running, it's time to develop that into a real world application. Instead of having to run `serverless deploy` everytime you make changes you wanna test, run `serverless dev`, which allows the CLI to watch for changes in your source directory as you develop, and deploy instantly on save.

To enable dev mode, simply run `serverless dev` from within the directory containing the `serverless.yml` file.

Expand All @@ -142,7 +142,7 @@ Dev mode also enables live streaming logs from your express app so that you can

Anytime you need to know more about your running express instance, you can run `serverless info` to view the most critical info. This is especially helpful when you want to know the outputs of your instances so that you can reference them in another instance. You will also see a url where you'll be able to view more info about your instance on the Serverless Dashboard.

It also shows you the status of your instance, when it was last deployed, and how many times it was deployed. To dig even deeper, you can pass the `--debug` flag to view the state of your component instance in case the deployment failed for any reason.
It also shows you the status of your instance, when it was last deployed, and how many times it was deployed. To dig even deeper, you can pass the `--debug` flag to view the state of your component instance in case the deployment failed for any reason.

### Remove

Expand Down Expand Up @@ -173,26 +173,22 @@ First, register your custom domain via Route53 on the AWS Acccount you are deplo
Next, add the domain to the `domain` in `inputs` in `serverless.yml`, like this:

```yaml
inputs:
src: ./
domain: serverlessexpress.com
```

You can also use a subdomain:

```yaml
inputs:
src: ./
domain: express.component-demos.com
```

Run `serverless deploy`.

Keep in mind, it will take AWS CloudFront and AWS Route53 and DNS up to 24 hours to propagate these changes and make your custom domain globally accessible. However, with recent AWS CloudFront speed increases, your domain should be accessible within ~20 minutes.
Keep in mind, it will take AWS CloudFront and AWS Route53 and DNS up to 24 hours to propagate these changes and make your custom domain globally accessible. However, with recent AWS CloudFront speed increases, your domain should be accessible within ~20 minutes.

#### Setting up domains registered outside of AWS

Expand All @@ -205,28 +201,25 @@ If your domain is not on AWS Route53, you will have to set this up manually beca
5. Notice the regional url that is returned as an output. Copy this URL, get back to your registrar and add another CNAME record with your domain or subdomain name and a value of this regional url. This ensures that your domain points to that cloudfront URL.
6. After around 20 mins, your SSL certificate and domain should all be working and pointing to your URL. Keep in mind that if you change the `name`, `stage`, `app` or `org` properties in `serverless.yml`, this would result in a completely new instance with a new cloudfront url. This allows you to setup different domains for each stage or instance


### Canary Deployments

At scale, when you want to push changes out to a small set of users, Serverless Express offers easy Canary Deployments out of the box!

This enables you to push out a version of your app (containing code changes you deem risky) which is only served to a percentage of traffic that you specificy (0-99%). This allows you to test big changes with little risk.
This enables you to push out a version of your app (containing code changes you deem risky) which is only served to a percentage of traffic that you specificy (0-99%). This allows you to test big changes with little risk.

To perform a canary deployment, first update your code with the potentially risky change.
To perform a canary deployment, first update your code with the potentially risky change.

Next, set a traffic weighting in your `serverless.yml` `inputs`:

```yaml
inputs:
src: ./
traffic: 0.5 # 50%
```

This tells Serverless Express to serve the new (potentially risky) code to 50% of the API requests, and the old (stable) code to the other 50% of requests.

Run `serverless deploy`. After deployment is complete, 50% of your requests will be randomly handled by the new experimental code.
Run `serverless deploy`. After deployment is complete, 50% of your requests will be randomly handled by the new experimental code.

You can slowly increment the percentage over time, just continue to re-deploy it.

Expand All @@ -236,16 +229,16 @@ If things are working, keep the new code, remove the `traffic` configuration opt

### Auto-Generate An OpenAPI V3 Specification From Your Express.js App

Version 1.1.0 introduced experimental support for a new feature called *"Inference"*.
Version 1.1.0 introduced experimental support for a new feature called _"Inference"_.

Inference attempts to run your application on each deployment and extract information from it.

The first feature Inference enables is detecting your API routes and converting them to the OpenAPI format, then adding them to the `outputs` of your Component Instance.

Currently, Inference is disabled by default. To enable it, add `inference: true` to your `serverless.yml` and ensure you are using the latest version of the Express coponent (>= 1.1.0).
Currently, Inference is disabled by default. To enable it, add `inference: true` to your `serverless.yml` and ensure you are using the latest version of the Express coponent (>= 1.1.0).

Given a lot of things can happen in your application upon starting it up, Inference does not work consistently. If it runs into an error trying to start your application, it will try its best to pass through useful errors to you so you can address what's blocking it from working.
Given a lot of things can happen in your application upon starting it up, Inference does not work consistently. If it runs into an error trying to start your application, it will try its best to pass through useful errors to you so you can address what's blocking it from working.

Overall, an OpenAPI specification generated by default is very powerful. This means you don't have to maintain that manually since it auto-updates on every deployment. (That's what serverless is all about!)
Overall, an OpenAPI specification generated by default is very powerful. This means you don't have to maintain that manually since it auto-updates on every deployment. (That's what serverless is all about!)

We will be adding many interesting features built on this. Extracting your endpoints and putting them into a common format was merely hte first step...
We will be adding many interesting features built on this. Extracting your endpoints and putting them into a common format was merely hte first step...
42 changes: 21 additions & 21 deletions src/_express/handler.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
'use strict'
'use strict';

const fs = require('fs')
const awsServerlessExpress = require('aws-serverless-express')
const fs = require('fs');
const awsServerlessExpress = require('aws-serverless-express');

exports.handler = async (event, context) => {
// remove AWS Lambda default handling of unhandled rejections
// this makes sure dev mode cli catches unhandled rejections
process.removeAllListeners('unhandledRejection')
process.removeAllListeners('unhandledRejection');

// make event object look like APIG 1.0
// until aws-serverless-express supports APIG 2.0
event.path = event.requestContext.http.path
event.method = event.requestContext.http.method
event.httpMethod = event.requestContext.http.method
event.path = event.requestContext.http.path;
event.method = event.requestContext.http.method;
event.httpMethod = event.requestContext.http.method;
// APIG 2.0 extracts cookies from headers automatically.
// We need to put `cookie` back to `headers.cookie` so it works with current aws-serverless-express
if (event.cookies && event.cookies.length > 0) {
event.headers.cookie = event.cookies.join('; ')
event.headers.cookie = event.cookies.join('; ');
}

// NOTICE: require() is relative to this file, while existsSync() is relative to the cwd, which is the root of lambda
let app
let app;
if (fs.existsSync('./app.js')) {
// load the user provided app

try {
// eslint-disable-next-line import/no-unresolved
app = require('../app.js')
app = require('../app.js');
} catch (e) {
if (e.message.includes("Cannot find module 'express'")) {
// user probably did not run "npm i". return a helpful message.
return {
statusCode: 404,
body:
'The "express" dependency was not found. Did you install "express" as a dependency within your source folder via npm?'
}
'The "express" dependency was not found. Did you install "express" as a dependency within your source folder via npm?',
};
}
// some other require error
return {
statusCode: 404,
body: e.message
}
body: e.message,
};
}
} else {
// load the built-in default app
app = require('../_src/app.js')
app = require('../_src/app.js');
}

if (typeof app !== 'function') {
// make sure user exported app in app.js or return a helpful message.
return {
statusCode: 404,
body:
'Express app not found. Please make sure you are exporting express from an "app.js" file.'
}
'Express app not found. Please make sure you are exporting express from an "app.js" file.',
};
}

const server = awsServerlessExpress.createServer(app)
const res = await awsServerlessExpress.proxy(server, event, context, 'PROMISE')
return res.promise
}
const server = awsServerlessExpress.createServer(app);
const res = await awsServerlessExpress.proxy(server, event, context, 'PROMISE');
return res.promise;
};
18 changes: 9 additions & 9 deletions src/_src/app.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict'
'use strict';

const express = require('express')
const express = require('express');

const app = express()
const app = express();

// Routes
app.get('/*', (req, res) => {
res.send(`Request received: ${req.method} - ${req.path}`)
})
res.send(`Request received: ${req.method} - ${req.path}`);
});

// Error handler
app.use((err, req, res) => {
console.error(err)
res.status(500).send('Internal Serverless Error')
})
console.error(err);
res.status(500).send('Internal Serverless Error');
});

module.exports = app
module.exports = app;
Loading

0 comments on commit 03b8ea2

Please sign in to comment.