Added more stuff

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2020-10-24 13:19:56 +05:30
parent f8aa241a14
commit 26648a79d9
5 changed files with 54 additions and 12 deletions

25
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: Node.js CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test

View File

@ -1,15 +1,27 @@
# 👷 `worker-template` Hello World # 👷 `url-short-cfw`
A template for kick starting a Cloudflare worker project. An Custom Build Link Shortener build with Cloudflare Workers
[`index.js`](https://github.com/cloudflare/worker-template/blob/master/index.js) is the content of the Workers script. ## Project Structure
#### Wrangler ```
.
├── .github # Auto Deploy and NODE CI scripts (`GitHub Actions Scripts`)
│ └── workflows
│ ├── cfw.js.yml # CloudFlare Worker auto deploy script
│ └── test.yml # NodeJS CI scripts
├── dist # Build Directory
│ └── worker.js # Initial CFW Worker file
├── index.js # Initial CFW Worker file
├── package.json # NodeJS package configuration
├── urls.json # Custom Url Endpoints
└── wrangler.toml # CFW wrangler config
```
## Build your Own
To generate using [wrangler](https://github.com/cloudflare/wrangler) To generate using [wrangler](https://github.com/cloudflare/wrangler)
``` ```
wrangler generate projectname https://github.com/cloudflare/worker-template wrangler generate <your-project-name> https://github.com/BRAVO68WEB/url-short-cfw
``` ```
Further documentation for Wrangler can be found [here](https://developers.cloudflare.com/workers/tooling/wrangler).

View File

@ -1,6 +1,6 @@
const urls = require('./urls.json') const urls = require('./urls.json')
addEventListener('fetch', (event) => { addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request)) event.respondWith(handleRequest(event.request))
}) })
@ -12,5 +12,9 @@ async function handleRequest(request) {
status: 308, status: 308,
headers: { location: urls[path] }, headers: { location: urls[path] },
}) })
else return new Response('404 not found?', { status: 404 }) else
return new Response(
'404 not found !! Check all possible at <a href="https://links.dfcommunity.win/all-urls"> Here </a>',
{ status: 404 },
)
} }

View File

@ -2,10 +2,10 @@
"private": true, "private": true,
"name": "url-shorter", "name": "url-shorter",
"version": "1.0.0", "version": "1.0.0",
"description": "A template for kick starting a Cloudflare Workers project", "description": "An Custom URL Shortener build on Cloud Flare Worker Platform",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "npm ci",
"format": "prettier --write '**/*.{js,css,json,md}'" "format": "prettier --write '**/*.{js,css,json,md}'"
}, },
"author": "Jyotirmoy <bravo68web@gmail.com>", "author": "Jyotirmoy <bravo68web@gmail.com>",

View File

@ -3,5 +3,6 @@
"df-cloud": "https://cloud.dfcommunity.win", "df-cloud": "https://cloud.dfcommunity.win",
"help": "https://github.com/bravo68web/url-short-cfw", "help": "https://github.com/bravo68web/url-short-cfw",
"df-api": "https://api.dfcommunity.win", "df-api": "https://api.dfcommunity.win",
"*": "https://github.com/" "all-urls": "https://raw.githubusercontent.com/BRAVO68WEB/url-short-cfw/master/urls.json",
"buildby": "https://github.com/bravo68web/"
} }