From 31f830265848271403f99346a4230d170d3bd92a Mon Sep 17 00:00:00 2001 From: rahulramesha Date: Tue, 2 Mar 2021 23:17:23 +0530 Subject: [PATCH] adding examples and linking repositories --- .gitignore | 2 +- .npmignore | 3 ++- examples/typescript/app.ts | 21 +++++++++++++++++++++ examples/typescript/index.ts | 16 ++++++++++++++++ examples/typescript/package.json | 22 ++++++++++++++++++++++ examples/typescript/router.ts | 26 ++++++++++++++++++++++++++ examples/typescript/statics/bar.html | 10 ++++++++++ examples/typescript/statics/bar.js | 1 + examples/typescript/statics/foo.html | 10 ++++++++++ examples/typescript/statics/foo.js | 1 + examples/typescript/tsconfig.json | 10 ++++++++++ package.json | 14 +++++++++++--- 12 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 examples/typescript/app.ts create mode 100644 examples/typescript/index.ts create mode 100644 examples/typescript/package.json create mode 100644 examples/typescript/router.ts create mode 100644 examples/typescript/statics/bar.html create mode 100644 examples/typescript/statics/bar.js create mode 100644 examples/typescript/statics/foo.html create mode 100644 examples/typescript/statics/foo.js create mode 100644 examples/typescript/tsconfig.json diff --git a/.gitignore b/.gitignore index 02f4b48..dca6fb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules -/package-lock.json +package-lock.json /lib diff --git a/.npmignore b/.npmignore index 615df90..da73548 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,7 @@ +/.github node_modules /examples /test -/package-lock.json +package-lock.json /.babelrc /.gitignore \ No newline at end of file diff --git a/examples/typescript/app.ts b/examples/typescript/app.ts new file mode 100644 index 0000000..b2c37c6 --- /dev/null +++ b/examples/typescript/app.ts @@ -0,0 +1,21 @@ +import express, {Request, Response } from 'express' +import path from 'path' + +import expressHttp2Bridge from 'http2-express-bridge' + +import route from './router' + +const staticPath = path.join(process.cwd(), './statics') +const app = expressHttp2Bridge(express) + +app.use(express.static(staticPath)) + +app.get('/path', (req: Request, res: Response) => { + const context = { site: req.hostname.split(".")[0] } + + res.send(`Hi There, ${context.site}`); +}) + +app.use(route) + +export default app diff --git a/examples/typescript/index.ts b/examples/typescript/index.ts new file mode 100644 index 0000000..b101685 --- /dev/null +++ b/examples/typescript/index.ts @@ -0,0 +1,16 @@ +import http2 from 'http2' +import { readFileSync } from 'fs' + +import app from './app' + +const PORT = 5000 + +let certs = { + key: readFileSync('C:/test/privateKey.key'), + cert: readFileSync('C:/test/certificate.crt'), + allowHTTP1: true +}; + +const server = http2.createSecureServer(certs, app) + +server.listen(PORT, ()=> {console.log(`listening on port ${PORT}`)}) \ No newline at end of file diff --git a/examples/typescript/package.json b/examples/typescript/package.json new file mode 100644 index 0000000..f98e245 --- /dev/null +++ b/examples/typescript/package.json @@ -0,0 +1,22 @@ +{ + "name": "typescript-example", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "start": "tsnd index.ts" + }, + "author": "Rahul R ", + "license": "ISC", + "dependencies": { + "express": "^4.17.1", + "http2-express-bridge": "^1.0.1" + }, + "devDependencies": { + "@types/express": "^4.17.11", + "@types/node": "^14.14.31", + "ts-node-dev": "^1.1.1", + "typescript": "^4.1.5" + } +} diff --git a/examples/typescript/router.ts b/examples/typescript/router.ts new file mode 100644 index 0000000..59f19e0 --- /dev/null +++ b/examples/typescript/router.ts @@ -0,0 +1,26 @@ +import {Router, Request, Response} from 'express' +import path from 'path' + +const router = Router() + +const staticPath = path.join(process.cwd(), './statics') + +router.get('/bar', (req: Request, res: Response) => { + + res.push(['/bar.js', '/foo.js'], staticPath) + res.send(` + + + + + Bar Document + + + This is a bar document. + + + + `); +}) + +export default router \ No newline at end of file diff --git a/examples/typescript/statics/bar.html b/examples/typescript/statics/bar.html new file mode 100644 index 0000000..7c1b284 --- /dev/null +++ b/examples/typescript/statics/bar.html @@ -0,0 +1,10 @@ + + + + + Bar Document + + + This is a bar document. + + \ No newline at end of file diff --git a/examples/typescript/statics/bar.js b/examples/typescript/statics/bar.js new file mode 100644 index 0000000..4595153 --- /dev/null +++ b/examples/typescript/statics/bar.js @@ -0,0 +1 @@ +console.log('is push working?') \ No newline at end of file diff --git a/examples/typescript/statics/foo.html b/examples/typescript/statics/foo.html new file mode 100644 index 0000000..a9478cd --- /dev/null +++ b/examples/typescript/statics/foo.html @@ -0,0 +1,10 @@ + + + + + Foo Document + + + This is a foo document. + + \ No newline at end of file diff --git a/examples/typescript/statics/foo.js b/examples/typescript/statics/foo.js new file mode 100644 index 0000000..4595153 --- /dev/null +++ b/examples/typescript/statics/foo.js @@ -0,0 +1 @@ +console.log('is push working?') \ No newline at end of file diff --git a/examples/typescript/tsconfig.json b/examples/typescript/tsconfig.json new file mode 100644 index 0000000..f296351 --- /dev/null +++ b/examples/typescript/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "strict": true, /* Enable all strict type-checking options. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} diff --git a/package.json b/package.json index 1dbb203..2f30faa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "http2-express-bridge", - "version": "1.0.0", + "version": "1.0.4", "description": "wrapper for express app to work with http2 protocol", "main": "lib/index.js", "module": "lib/index.js", @@ -16,7 +16,7 @@ "keywords": [ "express", "http2", - "server push" + "server-push" ], "dependencies": { "merge-descriptors": "^1.0.1", @@ -52,5 +52,13 @@ }, "engines": { "node": ">= 10.0.0" - } + }, + "repository": { + "type": "git", + "url": "https://github.com/rahulramesha/http2-express-bridge.git" + }, + "bugs": { + "url": "https://github.com/rahulramesha/http2-express-bridge/issues" + }, + "homepage": "https://github.com/rahulramesha/http2-express-bridge#readme" }