Skip to content

Commit

Permalink
adding examples and linking repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulramesha committed Mar 2, 2021
1 parent 180914a commit 31f8302
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
/package-lock.json
package-lock.json
/lib
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.github
node_modules
/examples
/test
/package-lock.json
package-lock.json
/.babelrc
/.gitignore
21 changes: 21 additions & 0 deletions examples/typescript/app.ts
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions examples/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -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}`)})
22 changes: 22 additions & 0 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"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"
}
}
26 changes: 26 additions & 0 deletions examples/typescript/router.ts
Original file line number Diff line number Diff line change
@@ -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(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bar Document</title>
</head>
<body>
This is a bar document.
<script src="/foo.js"></script>
<script src="/bar.js"></script>
</body>
</html>`);
})

export default router
10 changes: 10 additions & 0 deletions examples/typescript/statics/bar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bar Document</title>
</head>
<body>
This is a bar document.
</body>
</html>
1 change: 1 addition & 0 deletions examples/typescript/statics/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('is push working?')
10 changes: 10 additions & 0 deletions examples/typescript/statics/foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Foo Document</title>
</head>
<body>
This is a foo document.
</body>
</html>
1 change: 1 addition & 0 deletions examples/typescript/statics/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('is push working?')
10 changes: 10 additions & 0 deletions examples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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. */
}
}
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -16,7 +16,7 @@
"keywords": [
"express",
"http2",
"server push"
"server-push"
],
"dependencies": {
"merge-descriptors": "^1.0.1",
Expand Down Expand Up @@ -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"
}

0 comments on commit 31f8302

Please sign in to comment.