-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding examples and linking repositories
- Loading branch information
1 parent
180914a
commit 31f8302
Showing
12 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules | ||
/package-lock.json | ||
package-lock.json | ||
/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('is push working?') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('is push working?') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters