docs
This commit is contained in:
5
example/built-in/forbid/.local-web-server.json
Normal file
5
example/built-in/forbid/.local-web-server.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"forbid": [
|
||||
"/admin/*", "*.php"
|
||||
]
|
||||
}
|
1
example/built-in/forbid/admin/blocked.html
Normal file
1
example/built-in/forbid/admin/blocked.html
Normal file
@ -0,0 +1 @@
|
||||
<h1>Forbidden page</h1>
|
1
example/built-in/forbid/allowed.html
Normal file
1
example/built-in/forbid/allowed.html
Normal file
@ -0,0 +1 @@
|
||||
<h1>A permitted page</h1>
|
5
example/built-in/forbid/index.html
Normal file
5
example/built-in/forbid/index.html
Normal file
@ -0,0 +1,5 @@
|
||||
<h1>Forbidden routes</h1>
|
||||
|
||||
<p>
|
||||
Notice you can access <a href="allowed.html">this page</a>, but not <a href="admin/blocked.html">this admin page</a> or <a href="something.php">php file</a>.
|
||||
</p>
|
1
example/built-in/forbid/something.php
Normal file
1
example/built-in/forbid/something.php
Normal file
@ -0,0 +1 @@
|
||||
<?php echo "i'm coding PHP templatez!\n" ?>
|
5
example/built-in/mime-override/.local-web-server.json
Normal file
5
example/built-in/mime-override/.local-web-server.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"mime": {
|
||||
"text/plain": [ "php" ]
|
||||
}
|
||||
}
|
1
example/built-in/mime-override/something.php
Normal file
1
example/built-in/mime-override/something.php
Normal file
@ -0,0 +1 @@
|
||||
<?php echo "i'm coding PHP templatez!\n" ?>
|
8
example/built-in/mock-async/.local-web-server.json
Normal file
8
example/built-in/mock-async/.local-web-server.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"mocks": [
|
||||
{
|
||||
"route": "/",
|
||||
"module": "/mocks/delayed.js"
|
||||
}
|
||||
]
|
||||
}
|
11
example/built-in/mock-async/mocks/delayed.js
Normal file
11
example/built-in/mock-async/mocks/delayed.js
Normal file
@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
name: 'delayed response',
|
||||
response: function (ctx) {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
ctx.body = '<h1>You waited 2s for this</h1>'
|
||||
resolve()
|
||||
}, 2000)
|
||||
})
|
||||
}
|
||||
}
|
58
example/built-in/mock/.local-web-server.json
Normal file
58
example/built-in/mock/.local-web-server.json
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"mocks": [
|
||||
{
|
||||
"route": "/",
|
||||
"response": {
|
||||
"body": "<h1>Welcome to the Mock Responses example</h1>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"route": "/one",
|
||||
"response": {
|
||||
"type": "text/plain",
|
||||
"body": "<h1>Welcome to the Mock Responses example</h1>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"route": "/two",
|
||||
"request": { "accepts": "xml" },
|
||||
"response": {
|
||||
"body": "<result id='2' name='whatever' />"
|
||||
}
|
||||
},
|
||||
{
|
||||
"route": "/three",
|
||||
"responses": [
|
||||
{
|
||||
"request": { "method": "GET" },
|
||||
"response": {
|
||||
"body": "<h1>Mock response for 'GET' request on /three</h1>"
|
||||
}
|
||||
},
|
||||
{
|
||||
"request": { "method": "POST" },
|
||||
"response": {
|
||||
"status": 400,
|
||||
"body": { "message": "That method is not allowed." }
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"route": "/stream",
|
||||
"module": "/mocks/stream-self.js"
|
||||
},
|
||||
{
|
||||
"route": "/five/:id",
|
||||
"module": "/mocks/five.js"
|
||||
},
|
||||
{
|
||||
"route": "/users",
|
||||
"module": "/mocks/users.js"
|
||||
},
|
||||
{
|
||||
"route": "/users/:id",
|
||||
"module": "/mocks/user.js"
|
||||
}
|
||||
]
|
||||
}
|
6
example/built-in/mock/mocks/five.js
Normal file
6
example/built-in/mock/mocks/five.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
name: '/five/:id?name=:name',
|
||||
response: function (ctx, id) {
|
||||
ctx.body = `<h1>id: ${id}, name: ${ctx.query.name}</h1>`
|
||||
}
|
||||
}
|
8
example/built-in/mock/mocks/stream-self.js
Normal file
8
example/built-in/mock/mocks/stream-self.js
Normal file
@ -0,0 +1,8 @@
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = {
|
||||
name: 'stream response',
|
||||
response: {
|
||||
body: fs.createReadStream(__filename)
|
||||
}
|
||||
}
|
41
example/built-in/mock/mocks/user.js
Normal file
41
example/built-in/mock/mocks/user.js
Normal file
@ -0,0 +1,41 @@
|
||||
const users = require('./users.json')
|
||||
|
||||
/* responses for /users/:id */
|
||||
const mockResponses = [
|
||||
/* don't support POST here */
|
||||
{ request: { method: 'POST' }, response: { status: 400 } },
|
||||
|
||||
/* for GET requests, return a particular user */
|
||||
{
|
||||
name: 'GET user',
|
||||
request: { method: 'GET' },
|
||||
response: function (ctx, id) {
|
||||
ctx.body = users.find(user => user.id === Number(id))
|
||||
}
|
||||
},
|
||||
|
||||
/* for PUT requests, update the record */
|
||||
{
|
||||
name: 'PUT user',
|
||||
request: { method: 'PUT' },
|
||||
response: function (ctx, id) {
|
||||
const updatedUser = ctx.request.body
|
||||
const existingUserIndex = users.findIndex(user => user.id === Number(id))
|
||||
users.splice(existingUserIndex, 1, updatedUser)
|
||||
ctx.status = 200
|
||||
}
|
||||
},
|
||||
|
||||
/* DELETE request: remove the record */
|
||||
{
|
||||
name: 'DELETE user',
|
||||
request: { method: 'DELETE' },
|
||||
response: function (ctx, id) {
|
||||
const existingUserIndex = users.findIndex(user => user.id === Number(id))
|
||||
users.splice(existingUserIndex, 1)
|
||||
ctx.status = 200
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = mockResponses
|
32
example/built-in/mock/mocks/users.js
Normal file
32
example/built-in/mock/mocks/users.js
Normal file
@ -0,0 +1,32 @@
|
||||
const users = require('./users.json')
|
||||
|
||||
/* responses for /users */
|
||||
const mockResponses = [
|
||||
/* Respond with 400 Bad Request for PUT and DELETE - inappropriate on a collection */
|
||||
{ request: { method: 'PUT' }, response: { status: 400 } },
|
||||
{ request: { method: 'DELETE' }, response: { status: 400 } },
|
||||
{
|
||||
/* for GET requests return a subset of data, optionally filtered on 'minAge' and 'nationality' */
|
||||
request: { method: 'GET' },
|
||||
response: function (ctx) {
|
||||
ctx.body = users.filter(user => {
|
||||
const meetsMinAge = (user.age || 1000) >= (Number(ctx.query.minAge) || 0)
|
||||
const requiredNationality = user.nationality === (ctx.query.nationality || user.nationality)
|
||||
return meetsMinAge && requiredNationality
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
/* for POST requests, create a new user and return the path to the new resource */
|
||||
request: { method: 'POST' },
|
||||
response: function (ctx) {
|
||||
const newUser = ctx.request.body
|
||||
users.push(newUser)
|
||||
newUser.id = users.length
|
||||
ctx.status = 201
|
||||
ctx.response.set('Location', `/users/${newUser.id}`)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = mockResponses
|
5
example/built-in/mock/mocks/users.json
Normal file
5
example/built-in/mock/mocks/users.json
Normal file
@ -0,0 +1,5 @@
|
||||
[
|
||||
{ "id": 1, "name": "Lloyd", "age": 40, "nationality": "English" },
|
||||
{ "id": 2, "name": "Mona", "age": 34, "nationality": "Palestinian" },
|
||||
{ "id": 3, "name": "Francesco", "age": 24, "nationality": "Italian" }
|
||||
]
|
8
example/built-in/rewrite/.local-web-server.json
Normal file
8
example/built-in/rewrite/.local-web-server.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"rewrite": [
|
||||
{ "from": "/css/*", "to": "/build/styles/$1" },
|
||||
{ "from": "/npm/*", "to": "http://registry.npmjs.org/$1" },
|
||||
{ "from": "/broken/*", "to": "http://localhost:9999" },
|
||||
{ "from": "/:user/repos/:name", "to": "https://api.github.com/repos/:user/:name" }
|
||||
]
|
||||
}
|
4
example/built-in/rewrite/build/styles/style.css
Normal file
4
example/built-in/rewrite/build/styles/style.css
Normal file
@ -0,0 +1,4 @@
|
||||
body {
|
||||
font-family: monospace;
|
||||
font-size: 1.3em;
|
||||
}
|
24
example/built-in/rewrite/index.html
Normal file
24
example/built-in/rewrite/index.html
Normal file
@ -0,0 +1,24 @@
|
||||
<head>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
</head>
|
||||
<h1>Rewriting paths</h1>
|
||||
|
||||
<h2>Config</h2>
|
||||
<pre><code>
|
||||
{
|
||||
"rewrite": [
|
||||
{ "from": "/css/*", "to": "/build/styles/$1" },
|
||||
{ "from": "/npm/*", "to": "http://registry.npmjs.org/$1" },
|
||||
{ "from": "/broken/*", "to": "http://localhost:9999" },
|
||||
{ "from": "/:user/repos/:name", "to": "https://api.github.com/repos/:user/:name" }
|
||||
]
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<h2>Links</h2>
|
||||
<ul>
|
||||
<li><a href="/css/style.css">/css/style.css</li>
|
||||
<li><a href="/npm/local-web-server">/npm/local-web-server</a></li>
|
||||
<li><a href="/broken/">/broken/</a></li>
|
||||
<li><a href="/75lb/repos/work">/75lb/repos/work</a></li>
|
||||
</ul>
|
7
example/built-in/simple/css/style.css
Normal file
7
example/built-in/simple/css/style.css
Normal file
@ -0,0 +1,7 @@
|
||||
body {
|
||||
background-color: #AA3939;
|
||||
color: #FFE2E2
|
||||
}
|
||||
svg {
|
||||
fill: #000
|
||||
}
|
10
example/built-in/simple/index.html
Normal file
10
example/built-in/simple/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<head>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
</head>
|
||||
<h1>Amazing Page</h1>
|
||||
<p>
|
||||
With a freaky triangle..
|
||||
</p>
|
||||
<svg width="500" height="500">
|
||||
<polygon points="250,0 0,500 500,500"></polygon>
|
||||
</svg>
|
7
example/built-in/simple/package.json
Normal file
7
example/built-in/simple/package.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "example",
|
||||
"version": "1.0.0",
|
||||
"local-web-server": {
|
||||
"port": 8100
|
||||
}
|
||||
}
|
4
example/built-in/spa/.local-web-server.json
Normal file
4
example/built-in/spa/.local-web-server.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"spa": "index.html",
|
||||
"no-cache": true
|
||||
}
|
5
example/built-in/spa/css/style.css
Normal file
5
example/built-in/spa/css/style.css
Normal file
@ -0,0 +1,5 @@
|
||||
body {
|
||||
background-color: IndianRed;
|
||||
}
|
||||
|
||||
a { color: black }
|
BIN
example/built-in/spa/image.jpg
Normal file
BIN
example/built-in/spa/image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
14
example/built-in/spa/index.html
Normal file
14
example/built-in/spa/index.html
Normal file
@ -0,0 +1,14 @@
|
||||
<head>
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
</head>
|
||||
<h1>Single Page App</h1>
|
||||
<h2>Location: <span></span></h2>
|
||||
<ul>
|
||||
<li><a href="/login">/login</a></li>
|
||||
<li><a href="/search">/search</a></li>
|
||||
</ul>
|
||||
<p>Found asset: <img src="image.jpg" /></p>
|
||||
<p>Missing asset (should 404): <img src="sdafsadf.jpg" /></p>
|
||||
<script>
|
||||
document.querySelector('h2 span').textContent = window.location.pathname
|
||||
</script>
|
Reference in New Issue
Block a user