├── .github └── workflows │ ├── deno.yml │ └── test.yml ├── .releaserc.json ├── LICENSE ├── README.md ├── _config.yml ├── mod.ts └── mod_test.ts /.github/workflows/deno.yml: -------------------------------------------------------------------------------- 1 | name: Deno CI 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | build: 8 | name: ${{ matrix.kind }} ${{ matrix.os }} 9 | runs-on: ${{ matrix.os }} 10 | if: "!contains(github.event.head_commit.message, '[skip ci]')" 11 | strategy: 12 | matrix: 13 | os: [macOS-latest, ubuntu-latest, windows-latest] 14 | env: 15 | GH_ACTIONS: true 16 | DENO_BUILD_MODE: release 17 | V8_BINARY: true 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Setup Deno 21 | uses: denolib/setup-deno@master 22 | with: 23 | deno-version: 1.x 24 | - name: Tests 25 | run: deno test --allow-net 26 | release: 27 | name: Release 28 | runs-on: ubuntu-18.04 29 | if: "!contains(github.event.head_commit.message, '[skip ci]')" 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@v2 33 | - name: Setup Node.js 34 | uses: actions/setup-node@v1 35 | with: 36 | node-version: 12.17.0 37 | - name: Setup package.json 38 | run: echo '{"name":"@denorg/up","version":"0.0.0","publishConfig":{"access":"public"},"scripts":{"semantic-release":"semantic-release"},"repository":{"type":"git","url":"https://github.com/denorg/up.git"},"author":"Denorg ","license":"MIT","bugs":{"url":"https://github.com/denorg/up/issues"},"homepage":"https://denorg.github.io/up/","devDependencies":{"semantic-release":"^17.0.4","semantic-release-gitmoji":"^1.3.3"}}' > package.json 39 | - name: Install dependencies 40 | run: npm install 41 | - name: Release 42 | run: npx semantic-release 43 | env: 44 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 45 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 46 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test CI 2 | on: 3 | push: 4 | branches-ignore: 5 | - "master" 6 | pull_request: 7 | branches-ignore: 8 | - "master" 9 | jobs: 10 | build: 11 | name: ${{ matrix.kind }} ${{ matrix.os }} 12 | runs-on: ${{ matrix.os }} 13 | if: "!contains(github.event.head_commit.message, '[skip ci]')" 14 | strategy: 15 | matrix: 16 | os: [macOS-latest, ubuntu-latest, windows-latest] 17 | env: 18 | GH_ACTIONS: true 19 | DENO_BUILD_MODE: release 20 | V8_BINARY: true 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Setup Deno 24 | uses: denolib/setup-deno@master 25 | with: 26 | deno-version: 1.x 27 | - name: Run tests 28 | run: deno test --allow-net 29 | -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "semantic-release-gitmoji", 5 | { 6 | "releaseRules": { 7 | "patch": { 8 | "include": [":bento:", ":recycle:"] 9 | } 10 | } 11 | } 12 | ], 13 | "@semantic-release/github", 14 | "@semantic-release/npm" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Anand Chowdhary 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔌 Up 2 | 3 | Check if a website is up right now in Deno. 4 | 5 | [![Deno CI](https://github.com/denorg/up/workflows/Deno%20CI/badge.svg)](https://github.com/denorg/up/actions) 6 | [![GitHub](https://img.shields.io/github/license/denorg/up)](https://github.com/denorg/up/blob/master/LICENSE) 7 | [![Contributors](https://img.shields.io/github/contributors/denorg/up)](https://github.com/denorg/up/graphs/contributors) 8 | [![Deno Starter](https://img.shields.io/badge/deno-starter-brightgreen)](https://denorg.github.io/starter/) 9 | [![Made by Denorg](https://img.shields.io/badge/made%20by-denorg-0082fb)](https://github.com/denorg) 10 | [![TypeScript](https://img.shields.io/badge/types-TypeScript-blue)](https://github.com/denorg/up) 11 | [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) 12 | 13 | ## ⭐ Getting started 14 | 15 | Import the `isUp` function and use it: 16 | 17 | ```ts 18 | import { isUp } from "https://deno.land/x/up/mod.ts"; 19 | 20 | const result = await isUp("https://google.com"); // true 21 | ``` 22 | 23 | ### CLI with [DPX](https://github.com/denorg/dpx) 24 | 25 | After [installing DPX](https://github.com/denorg/dpx), you can directly use the CLI using the `dpx` command: 26 | 27 | ```bash 28 | dpx up https://google.com 29 | ``` 30 | 31 | ### CLI 32 | 33 | Alternatively, you can use it directly from the CLI: 34 | 35 | ```bash 36 | deno run --allow-net https://deno.land/x/up/mod.ts https://google.com 37 | ``` 38 | 39 | You can also install it globally using the following: 40 | 41 | ```bash 42 | deno install --allow-net -n up https://deno.land/x/up/mod.ts 43 | ``` 44 | 45 | Then, the package is available to run: 46 | 47 | ```bash 48 | up https://google.com # Result: https://google.com is up 49 | ``` 50 | 51 | ### Configuration 52 | 53 | Required permissions: 54 | 55 | 1. `--allow-net` 56 | 57 | ## 👩‍💻 Development 58 | 59 | Run tests: 60 | 61 | ```bash 62 | deno test --allow-net 63 | ``` 64 | 65 | ## ⭐ Related 66 | 67 | - [sindresorhus/is-up](https://github.com/sindresorhus/is-up) is the Node.js project serving as inspiration for this one 68 | - [sindresorhus/is-up-cli](https://github.com/sindresorhus/is-up-cli) is the CLI for `is-up` 69 | 70 | ## 📄 License 71 | 72 | MIT © [Denorg](https://den.org.in) 73 | 74 |

75 | 76 | 77 | 78 |

79 |

80 | A project by Denorg, the world's first Deno-focused community
organization and consulting company. Work with us →
81 |

82 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal 2 | -------------------------------------------------------------------------------- /mod.ts: -------------------------------------------------------------------------------- 1 | /** Check if a website is up */ 2 | export async function isUp(url: string): Promise { 3 | const host = encodeURIComponent((new URL(url)).host); 4 | const result: { 5 | "domain": string; 6 | "port": number; 7 | "status_code": 1 | 2 | 3; 8 | "response_ip": string; 9 | "response_code": number; 10 | "response_time": number; 11 | } = await (await fetch(`https://isitup.org/${host}.json`)) 12 | .json(); 13 | return result.status_code === 1; 14 | } 15 | 16 | for (let arg of Deno.args) { 17 | console.log(arg, await isUp(arg) ? " is up" : " is down"); 18 | } 19 | -------------------------------------------------------------------------------- /mod_test.ts: -------------------------------------------------------------------------------- 1 | import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; 2 | import { isUp } from "./mod.ts"; 3 | 4 | Deno.test("should be up", async (): Promise => { 5 | assertEquals(await isUp("https://google.com"), true); 6 | }); 7 | Deno.test("should be down", async (): Promise => { 8 | assertEquals( 9 | await isUp(`https://43rj90oq${Math.random().toString()}.com`), 10 | false, 11 | ); 12 | }); 13 | 14 | /** 15 | * The official website of deno is: https://deno.land/ 16 | * Website remote address: 172.67.163.168:443 17 | * The official website of Deno does not allow users to access content through IP addresses, 18 | * but in some cases, I may need this method to test my personal server. 19 | */ 20 | Deno.test("deno remote address test", async (): Promise => { 21 | assertEquals(await isUp("http://172.67.163.168:443"), true); 22 | }) 23 | --------------------------------------------------------------------------------