-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Simon Mackie
committed
May 20, 2022
0 parents
commit ba2f96f
Showing
150 changed files
with
5,887 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.swp | ||
*.xml~ | ||
*.rb~ | ||
*.css~ | ||
*.js~ | ||
tmp/ | ||
log/ | ||
.DS_Store | ||
|
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,19 @@ | ||
#!/usr/bin/env node | ||
|
||
// fetch name from command argument, environment, or fallback | ||
const nameArg = capitalize(process.argv[2] || process.env.USER || process.env.USERNAME || 'world'); | ||
|
||
// output message | ||
console.log(`Hello ${ nameArg }!`); | ||
|
||
// capitalize the first letter of all words | ||
function capitalize(str) { | ||
|
||
return str | ||
.trim() | ||
.toLowerCase() | ||
.split(' ') | ||
.map(word => word.charAt(0).toUpperCase() + word.slice(1)) | ||
.join(' '); | ||
|
||
} |
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,30 @@ | ||
#!/usr/bin/env node | ||
|
||
const | ||
port = (process.argv[2] || process.env.PORT || 3000), | ||
http = require('http'); | ||
|
||
http.createServer((req, res) => { | ||
|
||
console.log(req.url); | ||
const nameArg = capitalize( req.url.replace(/[^\w.,-]/g, ' ').replace(/\s+/g, ' ').trim() || 'world' ); | ||
|
||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/html'); | ||
res.end(`<p>Hello ${ nameArg }!</p>`); | ||
|
||
}).listen(port); | ||
|
||
console.log(`Server running at http://localhost:${ port }/`); | ||
|
||
// capitalize the first letter of all words | ||
function capitalize(str) { | ||
|
||
return str | ||
.trim() | ||
.toLowerCase() | ||
.split(' ') | ||
.map(word => word.charAt(0).toUpperCase() + word.slice(1)) | ||
.join(' '); | ||
|
||
} |
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 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen", | ||
"name": "nodemon", | ||
"program": "${workspaceFolder}/webhello.js", | ||
"request": "launch", | ||
"restart": true, | ||
"runtimeExecutable": "nodemon", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"type": "pwa-node" | ||
} | ||
] | ||
} |
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,37 @@ | ||
#!/usr/bin/env node | ||
|
||
const | ||
port = (process.argv[2] || process.env.PORT || 3000), | ||
http = require('http'); | ||
|
||
http.createServer((req, res) => { | ||
|
||
// abort favicon.ico request | ||
if (req.url.includes('favicon.ico')) { | ||
res.statusCode = 404; | ||
res.end('Not found'); | ||
return; | ||
} | ||
|
||
// handle other requests | ||
const nameArg = capitalize( req.url.replace(/[^\w.,-]/g, ' ').replace(/\s+/g, ' ').trim() || 'world' ); | ||
|
||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/html'); | ||
res.end(`<p>Hello ${ nameArg }!</p>`); | ||
|
||
}).listen(port); | ||
|
||
console.log(`Server running at http://localhost:${ port }/`); | ||
|
||
// capitalize the first letter of all words | ||
function capitalize(str) { | ||
|
||
return str | ||
.trim() | ||
.toLowerCase() | ||
.split(' ') | ||
.map(word => word.charAt(0).toUpperCase() + word.slice(1)) | ||
.join(' '); | ||
|
||
} |
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,15 @@ | ||
# Express Web Application Example | ||
|
||
To run this example, navigate to this directory in your terminal then install the Node.js dependencies with: | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
Run the application with: | ||
|
||
```sh | ||
npm start | ||
``` | ||
|
||
Then open paths at <http://localhost:3000/> in your web browser. |
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 @@ | ||
// Express.js application | ||
import express from 'express'; | ||
|
||
// configuration | ||
const | ||
cfg = { | ||
port: process.env.PORT || 3000 | ||
}; | ||
|
||
// Express initiation | ||
const app = express(); | ||
|
||
// home page route | ||
app.get('/', (req, res) => { | ||
res.send('Hello World!'); | ||
}); | ||
|
||
// another route | ||
app.get('/hello/', (req, res) => { | ||
res.send('Hello again!'); | ||
}); | ||
|
||
// start server | ||
app.listen(cfg.port, () => { | ||
console.log(`Example app listening at http://localhost:${ cfg.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,15 @@ | ||
{ | ||
"name": "express", | ||
"version": "1.0.0", | ||
"description": "Example Express.js app", | ||
"type": "module", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "nodemon index.js" | ||
}, | ||
"author": "Craig Buckler", | ||
"license": "MIT", | ||
"dependencies": { | ||
"express": "^4.17.1" | ||
} | ||
} |
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,15 @@ | ||
# Express Web Application Example | ||
|
||
To run this example, navigate to this directory in your terminal then install the Node.js dependencies with: | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
Run the application with: | ||
|
||
```sh | ||
npm start | ||
``` | ||
|
||
Then open paths at <http://localhost:3000/> in your web browser. |
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,60 @@ | ||
// Express.js application | ||
import express from 'express'; | ||
import compression from 'compression'; | ||
|
||
import { fileURLToPath } from 'url'; | ||
import { dirname, sep } from 'path'; | ||
|
||
// configuration | ||
const | ||
__dirname = dirname(fileURLToPath( import.meta.url )) + sep, | ||
cfg = { | ||
port: process.env.PORT || 3000, | ||
dir: { | ||
root: __dirname, | ||
static: __dirname + 'static' + sep | ||
} | ||
}; | ||
|
||
console.dir(cfg, { depth: null, color: true }); | ||
|
||
// Express initiation | ||
const app = express(); | ||
|
||
// do not identify Express | ||
app.disable('x-powered-by'); | ||
|
||
// HTTP compression | ||
app.use( compression() ); | ||
|
||
// log every request to the terminal | ||
app.use((req, res, next) => { | ||
console.log(req.url); | ||
next(); | ||
}); | ||
|
||
// home page route | ||
app.get('/', (req, res) => { | ||
res.send('Hello World!'); | ||
}); | ||
|
||
// another route | ||
app.get('/hello/', (req, res) => { | ||
res.send('Hello again!'); | ||
}); | ||
|
||
// serve static assets | ||
app.use(express.static( cfg.dir.static )); | ||
|
||
// 404 errors | ||
app.use((req, res) => { | ||
res.status(404).send('Not found'); | ||
}); | ||
|
||
// start server | ||
app.listen(cfg.port, () => { | ||
console.log(`Example app listening at http://localhost:${ cfg.port }`); | ||
}); | ||
|
||
// export defaults | ||
export { cfg, 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 @@ | ||
{ | ||
"name": "express", | ||
"version": "1.0.0", | ||
"description": "Example Express.js app", | ||
"type": "module", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "nodemon index.js" | ||
}, | ||
"author": "Craig Buckler", | ||
"license": "MIT", | ||
"dependencies": { | ||
"compression": "^1.7.4", | ||
"express": "^4.17.1" | ||
} | ||
} |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Static page</title> | ||
<meta name="viewport" content="width=device-width,initial-scale=1" /> | ||
</head> | ||
<body> | ||
|
||
<h1>This is a static page</h1> | ||
|
||
</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,15 @@ | ||
# Express Web Application Example | ||
|
||
To run this example, navigate to this directory in your terminal then install the Node.js dependencies with: | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
Run the application with: | ||
|
||
```sh | ||
npm start | ||
``` | ||
|
||
Then open paths at <http://localhost:3000/> in your web browser. |
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,65 @@ | ||
// Express.js application | ||
import express from 'express'; | ||
import compression from 'compression'; | ||
|
||
import { fileURLToPath } from 'url'; | ||
import { dirname, sep } from 'path'; | ||
|
||
// configuration | ||
const | ||
__dirname = dirname(fileURLToPath( import.meta.url )) + sep, | ||
cfg = { | ||
port: process.env.PORT || 3000, | ||
dir: { | ||
root: __dirname, | ||
static: __dirname + 'static' + sep, | ||
views: __dirname + 'views' + sep, | ||
routes: __dirname + 'routes' + sep, | ||
} | ||
}; | ||
|
||
console.dir(cfg, { depth: null, color: true }); | ||
|
||
// Express initiation | ||
const app = express(); | ||
|
||
// do not identify Express | ||
app.disable('x-powered-by'); | ||
|
||
// use EJS templates | ||
app.set('view engine', 'ejs'); | ||
app.set('views', cfg.dir.views); | ||
|
||
// HTTP compression | ||
app.use( compression() ); | ||
|
||
// log every request to the terminal | ||
app.use((req, res, next) => { | ||
console.log(req.url); | ||
next(); | ||
}); | ||
|
||
// home page route | ||
app.get('/', (req, res) => { | ||
res.render('message', { title: 'Hello World!' }); | ||
}); | ||
|
||
// /hello/ route | ||
import { helloRouter } from './routes/hello.js'; | ||
app.use('/hello', helloRouter); | ||
|
||
// serve static assets | ||
app.use(express.static( cfg.dir.static )); | ||
|
||
// 404 errors | ||
app.use((req, res) => { | ||
res.status(404).render('message', { title: 'Not found' }); | ||
}); | ||
|
||
// start server | ||
app.listen(cfg.port, () => { | ||
console.log(`Example app listening at http://localhost:${ cfg.port }`); | ||
}); | ||
|
||
// export defaults | ||
export { cfg, 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,12 @@ | ||
// localisation | ||
|
||
// international greetings | ||
export const hello = { | ||
au: 'G\'day', | ||
cn: 'Nǐ hǎo', | ||
en: 'Hello', | ||
de: 'Hallo', | ||
es: 'Hola', | ||
fr: 'Bonjour', | ||
jp: 'Kon\'nichiwa' | ||
}; |
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,13 @@ | ||
// string functions | ||
|
||
// capitalize the first letter of all words | ||
export function capitalize(str) { | ||
|
||
return str | ||
.trim() | ||
.toLowerCase() | ||
.split(' ') | ||
.map(word => word.charAt(0).toUpperCase() + word.slice(1)) | ||
.join(' '); | ||
|
||
} |
Oops, something went wrong.