Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
radyakaze committed Aug 12, 2024
0 parents commit 9df9cff
Show file tree
Hide file tree
Showing 32 changed files with 11,803 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: ci

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npx nypm@latest i

- name: Lint
run: npm run lint

test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npx nypm@latest i

- name: Playground prepare
run: npm run dev:prepare

- name: Test
run: npm run test
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Dependencies
node_modules

# Logs
*.log*

# Temp directories
.temp
.tmp
.cache

# Yarn
**/.yarn/cache
**/.yarn/*state*

# Generated dirs
dist

# Nuxt
.nuxt
.output
.data
.vercel_build_output
.build-*
.netlify

# Env
.env

# Testing
reports
coverage
*.lcov
.nyc_output

# VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Intellij idea
*.iml
.idea

# OSX
.DS_Store
.AppleDouble
.LSOverride
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint.experimental.useFlatConfig": true
}
925 changes: 925 additions & 0 deletions .yarn/releases/yarn-4.4.0.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
yarnPath: .yarn/releases/yarn-4.4.0.cjs

nodeLinker: node-modules
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Pringgo Radianto (Radya)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
117 changes: 117 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Here’s the updated `README.md` with contribution guidelines:

---

# Nuxt Proxy Party

`Nuxt Proxy Party` is a module designed to simplify the process of creating proxies using `h3-proxy` in your Nuxt application. This module allows you to easily define and manage proxy routes with custom handlers.

## Installation

To install `Nuxt Proxy Party`, run the following command:

```bash
yarn add -D nuxt-proxy-party
```

After installation, add the module to your `nuxt.config.ts`:

```typescript
export default defineNuxtConfig({
modules: ['nuxt-proxy-party'],
})
```

## Configuration

To initialize the configuration file, run:

```bash
npx nuxt-proxy-party --init
```

This will create a default configuration file that you can modify to suit your needs.

## Usage

To use Nuxt Proxy Party, you need to define your proxy routes within the `server.config.ts` file:

## Simple
```typescript
import { getCookie } from 'h3'
import { defineProxyParty } from 'nuxt-proxy-party/core'

export default defineProxyParty([
{
name: 'bin',
baseUrl: '/api/bin',
target: 'https://httpbin.org',
},
])
```

## With custom handler

```typescript
import { getCookie } from 'h3'
import { defineProxyParty } from 'nuxt-proxy-party/core'

export default defineProxyParty([
{
name: 'bin',
baseUrl: '/api/bin',
target: 'https://httpbin.org',
handler: (event) => {
const token = getCookie(event, 'oauth/token')

if (token) {
event.node.req.headers.authorization = `Bearer ${token}`
}
},
},
])
```

### Using Runtime Config

If you need to use runtime configuration, import it from `#imports`:

```typescript
import { useRuntimeConfig } from '#imports'
```

This allows you to access and use runtime configuration values in your proxy handler.

## Contributing

We welcome contributions to `Nuxt Proxy Party`. If you’d like to contribute, please follow these steps:

1. **Enable Corepack**: Ensure Corepack is enabled by running:
```bash
corepack enable
```

2. **Install Dependencies**: Install all necessary dependencies by running:
```bash
yarn install
```

3. **Generate Type Stubs**: Run the following command to generate type stubs:
```bash
yarn dev:prepare
```

4. **Start Development Mode**: Use the following command to start the playground in development mode:
```bash
yarn dev
```

This will set up your environment to develop and test `Nuxt Proxy Party`.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

---

This README now includes a section on how to contribute to the project, detailing the setup process for development.
16 changes: 16 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
{
input: './src/core',
name: 'core',
},
{
builder: 'mkdist',
input: 'src/bin',
outDir: 'dist/bin',
}

Check failure on line 13 in build.config.ts

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
],
externals: ['h3', 'consola'],
})
20 changes: 20 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-check
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'

// Run `npx @eslint/config-inspector` to inspect the resolved config interactively
export default createConfigForNuxt({
features: {
// Rules for module authors
tooling: true,
// Rules for formatting
stylistic: true,
},
dirs: {
src: [
'./playground',
],
},
})
.append(
// your custom flat config here...
)
52 changes: 52 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "nuxt-proxy-party",
"version": "1.0.0",
"description": "Nuxt HTTP proxy based on H3",
"repository": "radyakaze/nuxt-proxy-party",
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/types.d.ts",
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
}
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist"
],
"bin": "./dist/bin/index.mjs",
"scripts": {
"prepack": "nuxt-module-build build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
"release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint .",
"test": "vitest run",
"test:watch": "vitest watch",
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
},
"dependencies": {
"@nuxt/kit": "^3.12.4",
"citty": "^0.1.6"
},
"devDependencies": {
"@nuxt/devtools": "^1.3.9",
"@nuxt/eslint-config": "^0.3.13",
"@nuxt/module-builder": "^0.8.1",
"@nuxt/schema": "^3.12.4",
"@nuxt/test-utils": "^3.14.0",
"@types/node": "^20.14.11",
"@vitest/ui": "^2.0.5",
"changelogen": "^0.5.5",
"eslint": "^9.7.0",
"nuxt": "^3.12.4",
"typescript": "latest",
"vitest": "^2.0.5",
"vue-tsc": "^2.0.26"
},
"packageManager": "yarn@4.4.0"
}
8 changes: 8 additions & 0 deletions playground/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<div>
Nuxt module playground!
</div>
</template>

<script setup>
</script>
8 changes: 8 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default defineNuxtConfig({
modules: ['../src/module'],
runtimeConfig: {
apiUrl: '',
},
devtools: { enabled: true },
compatibilityDate: '2024-08-09',
})
13 changes: 13 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"name": "my-module-playground",
"type": "module",
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
"generate": "nuxi generate"
},
"dependencies": {
"nuxt": "^3.12.4"
}
}
Loading

0 comments on commit 9df9cff

Please sign in to comment.