Skip to content

Commit

Permalink
feat: transition to a pm2-managed project (#18)
Browse files Browse the repository at this point in the history
* feat: transition to a pm2-managed project
* test: add test coverage 💯
  • Loading branch information
e0ipso authored Oct 10, 2018
1 parent 737b915 commit aba476f
Show file tree
Hide file tree
Showing 18 changed files with 2,960 additions and 2,554 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"bio": "Engineer and programmer focused on online applications.",
"public_repos": 67,
"public_gists": 35,
"followers": 89,
"followers": 90,
"following": 45,
"created_at": "2011-10-20T14:27:43Z",
"updated_at": "2018-06-22T10:20:03Z"
Expand Down
9 changes: 7 additions & 2 deletions .emdaer/docs/local-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,23 @@ cors:
```
It is important to note that you can override configuration per environment.
That means that your `config/dev.yml` may contain:
That means that your `config/staging.yml` may contain:

```yaml
cms:
host: http://dev.example.com
host: http://stg.example.com
```

Learn more about configuration in the
[config module's documentation](https://www.npmjs.com/package/config).

### Start your server
Start your server with multiple threads serving requests (one per CPU core).
This uses the [PM2](https://pm2.io/doc/en/runtime/overview/) module. Edit the
[`ecosystem.config.js`](./ecosystem.config.js) file to tune how to start your
app. Read
[the documentation](https://pm2.io/doc/en/runtime/reference/ecosystem-file/) for
the PM2 ecosystem file.

```
npm start
Expand Down
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module.exports = {
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
env: { node: true },
plugins: ['prettier', 'flowtype'],
extends: ['problems', 'plugin:prettier/recommended'],
Expand Down
13 changes: 0 additions & 13 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
# DO NOT CHANGE THIS FILE. Instead create a new configuration file that holds
# the overwrites as explained in https://www.npmjs.com/package/config.

app:
name:
machine: 'contentajs'
human-readable: 'ContentaJS'
# The port for the server to listen on.
port: 3000

# The number of child processes to start. The total number of processes will be
# split between web workers. 0 will instruct the application to use the maximum
# number of processors available on the machine.
processes: 0
adiosSocket: ./adios.sock

cms:
# Add the URL including the protocol to your Contenta CMS installation.
# Example: https://www.example.com
Expand Down
File renamed without changes.
File renamed without changes.
24 changes: 0 additions & 24 deletions debug/singleWorker.js

This file was deleted.

13 changes: 9 additions & 4 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-->

<!--
emdaerHash:80c8315300ab5186215047df082ca38f
emdaerHash:a1d5fe3f5694380aacb3e6929e6d4022
-->

<h1 id="installation-img-align-right-src-logo-svg-alt-contenta-logo-title-contenta-logo-width-100-">Installation <img align="right" src="./logo.svg" alt="Contenta logo" title="Contenta logo" width="100"></h1>
Expand Down Expand Up @@ -54,16 +54,21 @@ cors:
- '*'
```
<p>It is important to note that you can override configuration per environment.
That means that your <code>config/dev.yml</code> may contain:</p>
That means that your <code>config/staging.yml</code> may contain:</p>
```yaml
cms:
host: http://dev.example.com
host: http://stg.example.com
```
<p>Learn more about configuration in the
<a href="https://www.npmjs.com/package/config">config module’s documentation</a>.</p>
<h3 id="start-your-server">Start your server</h3>
<p>Start your server with multiple threads serving requests (one per CPU core).</p>
<p>Start your server with multiple threads serving requests (one per CPU core).
This uses the <a href="https://pm2.io/doc/en/runtime/overview/">PM2</a> module. Edit the
<a href="./ecosystem.config.js"><code>ecosystem.config.js</code></a> file to tune how to start your
app. Read
<a href="https://pm2.io/doc/en/runtime/reference/ecosystem-file/">the documentation</a> for
the PM2 ecosystem file.</p>
<pre><code>
npm start
</code></pre>
Expand Down
28 changes: 28 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
apps: [
{
name: 'contentajs',
script: 'lib/server.js',

// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
port: 3000,
instances: 'max',
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'development',
},
env_staging: {
NODE_ENV: 'staging',
},
env_production: {
NODE_ENV: 'production',
},
},
],

// Use pm2 to deploy your ContentaJS app.
// @see https://pm2.io/doc/en/runtime/reference/ecosystem-file/#deploy-options
deploy: {},
};
7 changes: 5 additions & 2 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
'*.js': ['eslint --fix', 'prettier --write', 'git add'],
'.emdaer/**/*.md': ['emdaer', 'git add *.md'],
linters: {
'*.js': ['npm run prettier --', 'git add'],
'.emdaer/**/*.md': ['npm run documentation --', 'git add *.md'],
},
ignore: ['lib/**/*.js'],
};
Loading

0 comments on commit aba476f

Please sign in to comment.