Skip to content

Commit

Permalink
Release 1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeysedoy97 committed Mar 15, 2022
1 parent ba10ccc commit dab931c
Show file tree
Hide file tree
Showing 19 changed files with 2,838 additions and 320 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,json,toml}]
[*.{js,json,toml,yaml,yml,html,md}]
charset = utf-8
indent_size = 2
indent_style = space
25 changes: 19 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"extends": ["eslint:recommended", "plugin:node/recommended", "prettier"],
"env": {
"es2021": true,
"es2022": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:node/recommended", "plugin:github/recommended", "plugin:sonarjs/recommended", "prettier"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
}
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["node", "github", "sonarjs"],
"rules": {
"arrow-body-style": ["warn", "always"],
"camelcase": "warn",
Expand All @@ -19,22 +20,29 @@
"default-case-last": "warn",
"dot-notation": "warn",
"eqeqeq": "warn",
"eslint-comments/no-use": "off",
"filenames/match-regex": "off",
"i18n-text/no-en": "off",
"import/extensions": ["warn", "always"],
"import/no-unresolved": "off",
"no-duplicate-imports": "warn",
"no-lonely-if": "warn",
"no-return-assign": "warn",
"no-return-await": "warn",
"no-unused-vars": "warn",
"no-use-before-define": "warn",
"no-var": "warn",
"node/exports-style": ["warn", "module.exports"],
"node/file-extension-in-import": ["warn", "always"],
"node/no-missing-import": "off",
"node/no-unsupported-features/es-syntax": "warn",
"node/prefer-global/buffer": ["warn", "always"],
"node/prefer-global/console": ["warn", "always"],
"node/prefer-global/process": ["warn", "always"],
"node/prefer-global/text-decoder": ["warn", "always"],
"node/prefer-global/text-encoder": ["warn", "always"],
"node/prefer-global/url-search-params": ["warn", "always"],
"node/prefer-global/url": ["warn", "always"],
"node/prefer-global/url-search-params": ["warn", "always"],
"node/prefer-promises/dns": "warn",
"node/prefer-promises/fs": "warn",
"object-shorthand": "warn",
Expand All @@ -43,6 +51,11 @@
"prefer-rest-params": "warn",
"prefer-spread": "warn",
"require-await": "warn",
"sonarjs/cognitive-complexity": "off",
"sonarjs/no-duplicate-string": "warn",
"sonarjs/no-identical-functions": "warn",
"sonarjs/no-nested-switch": "off",
"sonarjs/no-small-switch": "warn",
"sort-imports": "warn",
"sort-keys": "warn",
"sort-vars": "warn"
Expand Down
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* text=auto

*.js text eol=lf
*.json text eol=lf
*.toml text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
*.html text eol=lf
*.md text eol=lf
19 changes: 4 additions & 15 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
---
jobs:
publish-github:
needs: test
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://npm.pkg.github.com/
- env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: npm publish
publish-npm:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: npm publish
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm ci --no-audit --ignore-scripts
- run: npm test
name: npm-publish
'on':
release:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/npm-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci --ignore-scripts
- run: npm test
strategy:
matrix:
node-version:
- 14
- 16
name: npm-test
'on': push
9 changes: 5 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/sh
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

volta run eslint --fix .
volta run prettier --write .
npm install --ignore-scripts --no-audit --no-fund
npm test
volta run --node 16 --bundled-npm -- npm install --ignore-scripts
volta run --node 16 --bundled-npm -- npm test
volta run --node 14 --bundled-npm -- npm test
cd example
npm install --ignore-scripts --no-audit --no-fund
volta run --node 16 --bundled-npm -- npm install
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
audit = false
fund = false
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"recommendations": [
"aaron-bond.better-comments",
"amatiasq.sort-imports",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"mgmcdermott.vscode-language-babel",
"sonarsource.sonarlint-vscode",
"visualstudioexptteam.vscodeintellicode"
]
}
8 changes: 4 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"editor.autoClosingQuotes": "always",
"editor.autoIndent": "full",
"editor.autoSurround": "languageDefined",
"editor.bracketPairColorization.enabled": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.foldingImportsByDefault": true,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.renderWhitespace": "all",
"editor.suggestSelection": "first",
"editor.tabSize": 2,
"eslint.format.enable": true,
Expand All @@ -15,8 +18,5 @@
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"git.autofetch": true,
"git.confirmSync": false,
"telemetry.enableCrashReporter": false,
"telemetry.enableTelemetry": false,
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue"
"git.confirmSync": false
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 sergeysedoy97
Copyright (c) 2022 sergeysedoy97

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
75 changes: 37 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,36 @@

---

## Example

Full example in `/example` folder.
## Install

```sh
npm install @awesomeorganization/static-handler
```
import { REDIRECT_STATUS_CODES, rewriteHandler } from '@awesomeorganization/rewrite-handler'

import { http } from '@awesomeorganization/servers'
import { staticHandler } from '@awesomeorganization/static-handler'
## Example

Full example in `/example` folder.

const example = async () => {
const rewriteMiddleware = rewriteHandler({
rules: [
{
pattern: '^/old-files/(.*)',
replacement: '/files/$1',
statusCode: REDIRECT_STATUS_CODES.MOVED_PERMANENTLY,
},
{
pattern: '(.*)/$',
replacement: '$1/index.txt',
},
],
})
const staticMiddleware = await staticHandler({
directoryPath: './static',
})
http({
listenOptions: {
host: '127.0.0.1',
port: 3000,
```js
const rewriteMiddleware = rewriteHandler({
rules: [
{
pattern: '^/old-files/(.*)',
replacement: '/files/$1',
statusCode: REDIRECT_STATUS_CODES.MOVED_PERMANENTLY,
},
onRequest(request, response) {
{
pattern: '(.*)/$',
replacement: '$1/index.txt',
},
],
})
const staticMiddleware = await staticHandler({
directoryPath: './static',
})
http({
handlers: {
request(request, response) {
rewriteMiddleware.handle({
request,
response,
Expand All @@ -55,14 +52,16 @@ const example = async () => {
response,
})
},
})
// TRY
// http://127.0.0.1:3000/
// http://127.0.0.1:3000/files/
// http://127.0.0.1:3000/files/somefile.txt
// http://127.0.0.1:3000/old-files/
// http://127.0.0.1:3000/old-files/somefile.txt
}
example()
},
listenOptions: {
host: '127.0.0.1',
port: 3000,
},
})
// TRY
// http://127.0.0.1:3000/
// http://127.0.0.1:3000/files/
// http://127.0.0.1:3000/files/somefile.txt
// http://127.0.0.1:3000/old-files/
// http://127.0.0.1:3000/old-files/somefile.txt
```
24 changes: 12 additions & 12 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable node/no-unsupported-features/es-syntax */

import { REDIRECT_STATUS_CODES, rewriteHandler } from '@awesomeorganization/rewrite-handler'

import { http } from '@awesomeorganization/servers'
Expand All @@ -23,20 +21,22 @@ const example = async () => {
directoryPath: './static',
})
http({
handlers: {
request(request, response) {
rewriteMiddleware.handle({
request,
response,
})
staticMiddleware.handle({
request,
response,
})
},
},
listenOptions: {
host: '127.0.0.1',
port: 3000,
},
onRequest(request, response) {
rewriteMiddleware.handle({
request,
response,
})
staticMiddleware.handle({
request,
response,
})
},
})
// TRY
// http://127.0.0.1:3000/
Expand Down

0 comments on commit dab931c

Please sign in to comment.