|
1 | | -# Serverless Node.js Starter |
| 1 | +# Serverless Stack Demo API |
2 | 2 |
|
3 | | -A Serverless starter that adds ES7 syntax, serverless-offline, linting, environment variables, and unit test support. Part of the [Serverless Stack](http://serverless-stack.com) guide. |
| 3 | +[Serverless Stack](http://serverless-stack.com) is a free comprehensive guide to creating full-stack serverless applications. We create a [note taking app](http://demo2.serverless-stack.com) from scratch. |
4 | 4 |
|
5 | | -[Serverless Node.js Starter](https://github.com/AnomalyInnovations/serverless-nodejs-starter) uses the [serverless-bundle](https://github.com/AnomalyInnovations/serverless-bundle) plugin (an extension of the [serverless-webpack](https://github.com/serverless-heaven/serverless-webpack) plugin) and the [serverless-offline](https://github.com/dherault/serverless-offline) plugin. It supports: |
| 5 | +This repo is for the serverless backend API that we build over the course of the tutorial. You can find the repo for the frontend React app [here](https://github.com/AnomalyInnovations/serverless-stack-demo-client). And the repo for the tutorial [here](https://github.com/AnomalyInnovations/serverless-stack-com). |
6 | 6 |
|
7 | | -- **Generating optimized Lambda packages with Webpack** |
8 | | -- **Use ES7 syntax in your handler functions** |
9 | | - - Use `import` and `export` |
10 | | -- **Run API Gateway locally** |
11 | | - - Use `serverless offline start` |
12 | | -- **Support for unit tests** |
13 | | - - Run `npm test` to run your tests |
14 | | -- **Sourcemaps for proper error messages** |
15 | | - - Error message show the correct line numbers |
16 | | - - Works in production with CloudWatch |
17 | | -- **Lint your code with ESLint** |
18 | | -- **Add environment variables for your stages** |
19 | | -- **No need to manage Webpack or Babel configs** |
| 7 | +#### Steps |
20 | 8 |
|
21 | | ---- |
22 | | - |
23 | | -### Demo |
24 | | - |
25 | | -A demo version of this service is hosted on AWS - [`https://z6pv80ao4l.execute-api.us-east-1.amazonaws.com/dev/hello`](https://z6pv80ao4l.execute-api.us-east-1.amazonaws.com/dev/hello) |
26 | | - |
27 | | -And here is the ES7 source behind it |
28 | | - |
29 | | -``` javascript |
30 | | -export const hello = async (event, context) => { |
31 | | - return { |
32 | | - statusCode: 200, |
33 | | - body: JSON.stringify({ |
34 | | - message: `Go Serverless v1.0! ${(await message({ time: 1, copy: 'Your function executed successfully!'}))}`, |
35 | | - input: event, |
36 | | - }), |
37 | | - }; |
38 | | -}; |
39 | | - |
40 | | -const message = ({ time, ...rest }) => new Promise((resolve, reject) => |
41 | | - setTimeout(() => { |
42 | | - resolve(`${rest.copy} (with a delay)`); |
43 | | - }, time * 1000) |
44 | | -); |
45 | | -``` |
46 | | - |
47 | | -### Upgrading from v1.x |
48 | | - |
49 | | -We have detailed instructions on how to upgrade your app to the v2.0 of the starter if you were using v1.x before. [Read about it here](https://github.com/AnomalyInnovations/serverless-nodejs-starter/releases/tag/v2.0). |
50 | | - |
51 | | -### Requirements |
52 | | - |
53 | | -- [Install the Serverless Framework](https://serverless.com/framework/docs/providers/aws/guide/installation/) |
54 | | -- [Configure your AWS CLI](https://serverless.com/framework/docs/providers/aws/guide/credentials/) |
55 | | - |
56 | | -### Installation |
57 | | - |
58 | | -To create a new Serverless project. |
59 | | - |
60 | | -``` bash |
61 | | -$ serverless install --url https://github.com/AnomalyInnovations/serverless-nodejs-starter --name my-project |
62 | | -``` |
63 | | - |
64 | | -Enter the new directory |
65 | | - |
66 | | -``` bash |
67 | | -$ cd my-project |
68 | | -``` |
69 | | - |
70 | | -Install the Node.js packages |
71 | | - |
72 | | -``` bash |
73 | | -$ npm install |
74 | | -``` |
75 | | - |
76 | | -### Usage |
77 | | - |
78 | | -To run a function on your local |
79 | | - |
80 | | -``` bash |
81 | | -$ serverless invoke local --function hello |
82 | | -``` |
| 9 | +This branch in the repo is related to one of the steps in the guide. Here is an index of the various steps in order. |
83 | 10 |
|
84 | | -To simulate API Gateway locally using [serverless-offline](https://github.com/dherault/serverless-offline) |
85 | | - |
86 | | -``` bash |
87 | | -$ serverless offline start |
88 | | -``` |
89 | | - |
90 | | -Deploy your project |
91 | | - |
92 | | -``` bash |
93 | | -$ serverless deploy |
94 | | -``` |
95 | | - |
96 | | -Deploy a single function |
97 | | - |
98 | | -``` bash |
99 | | -$ serverless deploy function --function hello |
100 | | -``` |
101 | | - |
102 | | -#### Running Tests |
103 | | - |
104 | | -Run your tests using |
105 | | - |
106 | | -``` bash |
107 | | -$ npm test |
108 | | -``` |
109 | | - |
110 | | -We use Jest to run our tests. You can read more about setting up your tests [here](https://facebook.github.io/jest/docs/en/getting-started.html#content). |
111 | | - |
112 | | -#### Environment Variables |
113 | | - |
114 | | -To add environment variables to your project |
115 | | - |
116 | | -1. Rename `env.example` to `.env`. |
117 | | -2. Add environment variables for your local stage to `.env`. |
118 | | -3. Uncomment `environment:` block in the `serverless.yml` and reference the environment variable as `${env:MY_ENV_VAR}`. Where `MY_ENV_VAR` is added to your `.env` file. |
119 | | -4. Make sure to not commit your `.env`. |
120 | | - |
121 | | -#### Linting |
122 | | - |
123 | | -We use [ESLint](https://eslint.org) to lint your code via the [serverless-bundle](https://github.com/AnomalyInnovations/serverless-bundle) plugin. |
124 | | - |
125 | | -You can turn this off by adding the following to your `serverless.yml`. |
126 | | - |
127 | | -``` yaml |
128 | | -custom: |
129 | | - bundle: |
130 | | - linting: false |
131 | | -``` |
132 | | -
|
133 | | -To [override the default config](https://eslint.org/docs/user-guide/configuring), add a `.eslintrc.json` file. To ignore ESLint for specific files, add it to a `.eslintignore` file. |
134 | | - |
135 | | -### Support |
136 | | - |
137 | | -- Open a [new issue](https://github.com/AnomalyInnovations/serverless-nodejs-starter/issues/new) if you've found a bug or have some suggestions. |
138 | | -- Or submit a pull request! |
| 11 | +- [Initialize the Backend Repo](../../tree/initialize-the-backend-repo) |
| 12 | +- [Handle API Gateway CORS Errors](../../tree/handle-api-gateway-cors-errors) |
| 13 | +- [Deploy Your Serverless Infrastructure](../../tree/deploy-your-serverless-infrastructure) |
139 | 14 |
|
140 | 15 | --- |
141 | 16 |
|
142 | 17 | This repo is maintained by [Anomaly Innovations](https://anoma.ly); makers of [Seed](https://seed.run) and [Serverless Stack](https://serverless-stack.com). |
| 18 | + |
| 19 | +[Email]: mailto:contact@anoma.ly |
0 commit comments