├── vendor └── .empty ├── .gitignore ├── index.js ├── lib ├── install.js ├── suffix.js └── index.js ├── .editorconfig ├── .github ├── dependabot.yml └── workflows │ └── test.yml ├── test └── test.js ├── readme.md └── package.json /vendor/.empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.pem 3 | vendor 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import lib from './lib/index.js'; 2 | 3 | export default lib.path(); 4 | -------------------------------------------------------------------------------- /lib/install.js: -------------------------------------------------------------------------------- 1 | import index from './index.js'; 2 | 3 | index.findExisting(); 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_size = 2 5 | indent_style = space 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: weekly 7 | time: "20:00" 8 | open-pull-requests-limit: 10 9 | ignore: 10 | - dependency-name: xo 11 | versions: 12 | - 0.37.1 13 | - 0.38.1 14 | - 0.38.2 15 | -------------------------------------------------------------------------------- /lib/suffix.js: -------------------------------------------------------------------------------- 1 | import process from 'node:process'; 2 | 3 | export default function suffix() { 4 | switch (process.platform) { 5 | case 'darwin': 6 | return '_darwin_amd64'; 7 | case 'win32': 8 | return '_windows_amd64'; 9 | case 'linux': 10 | switch (process.arch) { 11 | case 'arm': 12 | return '_linux_arm'; 13 | case 'x64': 14 | return '_linux_amd64'; 15 | default: 16 | return '_linux_386'; 17 | } 18 | 19 | default: 20 | throw new Error(`No binary for ${process.platform}/${process.arch}`); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }} 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 14 14 | - 12 15 | os: 16 | - ubuntu-latest 17 | - macos-latest 18 | - windows-latest 19 | steps: 20 | - uses: actions/checkout@v2 21 | - uses: actions/setup-node@v2 22 | with: 23 | node-version: ${{ matrix.node-version }} 24 | - run: npm install 25 | - run: npm test 26 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | import process from 'node:process'; 3 | import {fileURLToPath} from 'node:url'; 4 | import BinWrapper from 'bin-wrapper'; 5 | import suffix from './suffix.js'; 6 | 7 | const url = 'https://github.com/GoogleChromeLabs/simplehttp2server/releases/download/3.1.3/'; 8 | const extension = process.platform === 'win32' ? '.exe' : ''; 9 | const filename = `simplehttp2server${suffix()}${extension}`; 10 | const currentDirectory = path.dirname(fileURLToPath(import.meta.url)); 11 | 12 | const index = new BinWrapper() 13 | .src(`${url}${filename}`) 14 | .dest(path.resolve(currentDirectory, '..', 'vendor')) 15 | .use(filename); 16 | 17 | export default index; 18 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import {execa} from 'execa'; 3 | import simplehttp2server from '../index.js'; 4 | 5 | test('return path to binary and verify that it is working', async t => { 6 | let output = ''; 7 | try { 8 | output += await execa(simplehttp2server, ['--help']); 9 | } catch (error) { 10 | // It will fail, as the exit status code of the executable is 2 11 | output += error; 12 | } 13 | 14 | if ( 15 | /Usage of/m.test(output) 16 | && /-config string/m.test(output) 17 | && /-cors string/m.test(output) 18 | && /-listen string/m.test(output) 19 | ) { 20 | t.pass(); 21 | } else { 22 | t.fail(`output: ${output}`); 23 | } 24 | }); 25 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # simplehttp2server ![GitHub Actions Status](https://github.com/1000ch/simplehttp2server/workflows/test/badge.svg?branch=main) 2 | 3 | > [simplehttp2server](https://github.com/GoogleChromeLabs/simplehttp2server) serves the current directory on an HTTP/2.0 capable server. This server is for development purposes only. 4 | 5 | You probably want [simplehttp2server-cli](https://github.com/1000ch/simplehttp2server-cli) instead. 6 | 7 | ## Install 8 | 9 | ``` 10 | $ npm install --save simplehttp2server 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | import {execFile} from 'node:child_process'; 17 | import simplehttp2server from 'simplehttp2server'; 18 | 19 | execFile(simplehttp2server, error => { 20 | console.log('simplehttp2server is starting!'); 21 | }); 22 | ``` 23 | 24 | ## License 25 | 26 | [MIT](https://1000ch.mit-license.org) © [Shogo Sensui](https://github.com/1000ch) 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simplehttp2server", 3 | "version": "5.0.0", 4 | "description": "simplehttp2server wrapper that makes it seamlessly available as a local dependency", 5 | "license": "MIT", 6 | "repository": "1000ch/simplehttp2server", 7 | "author": { 8 | "name": "Shogo Sensui", 9 | "email": "shogosensui@gmail.com", 10 | "url": "https://github.com/1000ch" 11 | }, 12 | "engines": { 13 | "node": ">=12.20" 14 | }, 15 | "type": "module", 16 | "scripts": { 17 | "postinstall": "node lib/install.js", 18 | "test": "xo && ava" 19 | }, 20 | "files": [ 21 | "index.js", 22 | "lib" 23 | ], 24 | "keywords": [ 25 | "server", 26 | "http", 27 | "http2" 28 | ], 29 | "bugs": { 30 | "url": "https://github.com/1000ch/simplehttp2server/issues" 31 | }, 32 | "homepage": "https://github.com/1000ch/simplehttp2server#readme", 33 | "dependencies": { 34 | "bin-wrapper": "^4.1.0" 35 | }, 36 | "devDependencies": { 37 | "ava": "^4.0.0", 38 | "execa": "^6.0.0", 39 | "tempy": "^2.0.0", 40 | "xo": "^0.47.0" 41 | }, 42 | "xo": { 43 | "space": 2 44 | } 45 | } 46 | --------------------------------------------------------------------------------