Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Metarhia template #32

Merged
merged 1 commit into from
Nov 2, 2023
Merged
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
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

[{*.js,*.mjs,*.ts,*.json,*.yml}]
indent_size = 2
indent_style = space
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
14 changes: 6 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"extends": ["metarhia", "plugin:prettier/recommended"],
"env": {
"es2021": true,
"node": true,
"browser": true
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {}
"ecmaVersion": "latest"
}
}
21 changes: 11 additions & 10 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ jobs:
- run: npm run prettier:check
- run: npm run eslint:check
- run: npm run test
deploy:
runs-on: ubuntu-latest
needs: [test, analyze]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
# TODO: Add deploy job
# deploy:
# runs-on: ubuntu-latest
# needs: [test, analyze]
# if: github.ref == 'refs/heads/main'
# steps:
# - uses: actions/checkout@v3
# - uses: superfly/flyctl-actions/setup-flyctl@master
# - run: flyctl deploy --remote-only
# env:
# FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
7 changes: 5 additions & 2 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const toRelative = require('./src/utils/relativePath.js');
const path = require('node:path');

const relative = (files) =>
files.map((file) => path.relative(process.cwd(), file)).join(' ');

module.exports = {
'*': 'prettier --check --ignore-unknown',
'*.js': 'eslint --cache',
'*.{js,ts}': () => 'npm run typescript:check',
'*': (files) =>
`cspell --show-suggestions --quiet --gitignore ${toRelative(files)}`,
`cspell --show-suggestions --quiet --gitignore ${relative(files)}`,
};
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
prisma/**/
application/tasks/
11 changes: 8 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true
"singleQuote": true,
"trailingComma": "all",
"overrides": [
{
"files": ["**/.*rc", "**/*.json"],
"options": { "parser": "json" }
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[ERD](./prisma/README.md)
# 🦾 Back-end part of the messenger application
20 changes: 0 additions & 20 deletions api/.eslintrc.json

This file was deleted.

7 changes: 0 additions & 7 deletions api/user.js

This file was deleted.

19 changes: 19 additions & 0 deletions application/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"parserOptions": {
"sourceType": "module"
},
"rules": {
"id-denylist": [
2,
"application",
"node",
"npm",
"api",
"lib",
"db",
"domain",
"config",
"metarhia"
]
}
}
16 changes: 16 additions & 0 deletions application/api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"globals": {
"api": "readonly",
"application": "readonly",
"config": "readonly",
"context": "readonly",
"node": "readonly",
"npm": "readonly",
"lib": "readonly",
"db": "readonly",
"bus": "readonly",
"domain": "readonly",
"metarhia": "readonly",
"DomainError": "readonly"
}
}
15 changes: 15 additions & 0 deletions application/api/example/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
({
access: 'public',

parameters: {
a: 'number',
b: 'number',
},

method: async ({ a, b }) => {
const result = a + b;
return result;
},

returns: 'number',
});
24 changes: 24 additions & 0 deletions application/cert/default/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generate certificates

## Certbot (for production)

- Let's Encrypt is a free certificate authority: https://letsencrypt.org/
- Use Certbot (free tool for automatically using Let’s Encrypt certificates on
manually-administrated websites to enable HTTPS): https://certbot.eff.org/

```
dnf -y install certbot
certbot certonly --standalone -d www.domain.com -d domain.com -m [email protected] --agree-tos --no-eff-email
yes | cp /etc/letsencrypt/live/domain.com/fullchain.pem ~/domain.com/application/cert/cert.pem
yes | cp /etc/letsencrypt/live/domain.com/privkey.pem ~/domain.com/application/cert/key.pem
```

Or use impress web server for challenge exchange:

```
certbot certonly --webroot -w ~/domain.com/application/static -d www.domain.com -d domain.com -m [email protected] --agree-tos --no-eff-email
```

## Self-signed (for testing)

- Run `./generate.sh` in this directory
12 changes: 12 additions & 0 deletions application/cert/default/generate.ext
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = example.com
DNS.2 = hello.example.com
DNS.3 = hello1.example.com
DNS.4 = hello2.example.com
IP.1 = 127.0.0.1
IP.2 = ::1
5 changes: 5 additions & 0 deletions application/cert/default/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cd "$(dirname "$0")"
openssl genrsa -out key.pem 3072
openssl req -new -out self.pem -key key.pem -subj '/CN=localhost'
openssl req -text -noout -in self.pem
openssl x509 -req -days 1024 -in self.pem -signkey key.pem -out cert.pem -extfile generate.ext
5 changes: 5 additions & 0 deletions application/config/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"strict": ["error", "never"]
}
}
7 changes: 7 additions & 0 deletions application/config/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
({
keepDays: 100,
writeInterval: 3000,
writeBuffer: 64 * 1024,
toFile: ['error', 'warn', 'info', 'debug', 'log'],
toStdout: ['error', 'warn', 'info', 'debug', 'log'],
});
7 changes: 7 additions & 0 deletions application/config/scale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
({
cloud: 'PrivateCloud',
server: '1',
instance: 'standalone',
token: '2aC8F1-W9gM2*2-p=9g6xs2Q4v7e1kw-',
gc: 60 * 60 * 1000,
});
32 changes: 32 additions & 0 deletions application/config/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
({
host: '0.0.0.0',
protocol: 'http',
ports: [8000],
nagle: false,
timeouts: {
bind: 2000,
start: 30000,
stop: 5000,
request: 5000,
watch: 1000,
test: 60000,
},
queue: {
concurrency: 1000,
size: 2000,
timeout: 3000,
},
scheduler: {
concurrency: 10,
size: 2000,
timeout: 3000,
},
workers: {
pool: 0,
wait: 2000,
timeout: 5000,
},
cors: {
origin: '*',
},
});
13 changes: 13 additions & 0 deletions application/config/sessions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
({
sid: 'token',
characters: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
length: 64,
secret: 'secret',
regenerate: 60 * 60 * 1000,
expire: 2 * 60 * 60 * 1000,
persistent: true,
limits: {
ip: 20,
user: 5,
},
});
9 changes: 9 additions & 0 deletions application/static/.404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<title>404 Not found</title>
</head>
<body>
<h1>404 Not found</h1>
</body>
</html>
13 changes: 13 additions & 0 deletions application/static/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"parserOptions": {
"sourceType": "module"
},
"globals": {
"application": "readonly",
"api": "readonly"
},
"rules": {
"id-denylist": [2, "global"],
"import/no-unresolved": "off"
}
}
9 changes: 9 additions & 0 deletions application/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
Metarhia application server repository template
</body>
</html>
23 changes: 0 additions & 23 deletions config/index.js

This file was deleted.

25 changes: 0 additions & 25 deletions global.d.ts

This file was deleted.

Loading