-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 3c9e6f8
Showing
22 changed files
with
329 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,2 @@ | ||
|
||
node_modules |
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,162 @@ | ||
# Getting Start | ||
|
||
## prepare | ||
|
||
``` | ||
npm init | ||
npm install --save base2 | ||
``` | ||
|
||
## hello world | ||
|
||
create app.js | ||
|
||
``` | ||
var app = require('../')({ | ||
// debug: true, | ||
root:__dirname | ||
}) | ||
app.get('/', function(req, res){ | ||
res.json({hello: 'world'}); | ||
}) | ||
app.start(3029); | ||
``` | ||
|
||
run | ||
|
||
``` | ||
npm run 1 | ||
``` | ||
|
||
open in browser | ||
|
||
- http://127.0.0.1:3029/ | ||
|
||
## mount routes from folder | ||
|
||
install express | ||
|
||
``` | ||
npm i --save express | ||
``` | ||
|
||
create app.js | ||
|
||
``` | ||
var app = require('base2')({ | ||
// debug: true, | ||
root:__dirname, | ||
"routes": "routes", | ||
}); | ||
app.start(3029); | ||
``` | ||
|
||
create routes folder | ||
|
||
routes/index.js | ||
|
||
``` | ||
var express = require('express'); | ||
var router = express.Router(); | ||
/* GET home page. */ | ||
router.get('/', function(req, res, next) { | ||
res.send('respond with a routes /'); | ||
}); | ||
module.exports = router; | ||
``` | ||
|
||
routes/users.js | ||
|
||
``` | ||
var express = require('express'); | ||
var router = express.Router(); | ||
/* GET users listing. */ | ||
router.get('/', function(req, res, next) { | ||
res.send('respond with a resource /users'); | ||
}); | ||
module.exports = router; | ||
``` | ||
|
||
run | ||
|
||
``` | ||
npm run 2 | ||
``` | ||
|
||
open in browser | ||
|
||
- http://127.0.0.1:3029/ | ||
- http://127.0.0.1:3029/users | ||
|
||
## views engine with jade | ||
|
||
duplicate mount-routes with views-jade | ||
|
||
install jade | ||
|
||
``` | ||
npm i --save jade | ||
``` | ||
|
||
modify app.js | ||
|
||
``` | ||
var app = require('base2')({ | ||
// debug: true, | ||
root:__dirname, | ||
"routes": "routes", | ||
"views" : "views" | ||
}); | ||
app.start(3029); | ||
``` | ||
|
||
only add views option | ||
|
||
run | ||
|
||
``` | ||
npm run 3 | ||
``` | ||
|
||
## static server | ||
|
||
### simple static server | ||
|
||
``` | ||
var app = require('base2')({ | ||
// debug: true, | ||
root:__dirname, | ||
"public": "public", | ||
}) | ||
app.start(3029); | ||
``` | ||
|
||
only add public option | ||
|
||
run | ||
|
||
``` | ||
npm run 4 | ||
``` | ||
|
||
### static server 2 | ||
|
||
with views | ||
|
||
run | ||
|
||
``` | ||
npm run 5 | ||
``` | ||
|
||
- http://127.0.0.1:3029/ | ||
- http://127.0.0.1:3029/index.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,10 @@ | ||
var app = require('base2')({ | ||
// debug: true, | ||
root:__dirname | ||
}) | ||
|
||
app.get('/', function(req, res){ | ||
res.json({hello: 'world'}); | ||
}) | ||
|
||
app.start(3029); |
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,7 @@ | ||
var app = require('base2')({ | ||
debug: true, | ||
root:__dirname, | ||
"routes": "routes", | ||
}); | ||
|
||
app.start(3029); |
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 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET home page. */ | ||
router.get('/', function(req, res, next) { | ||
res.send('respond with a routes /'); | ||
}); | ||
|
||
module.exports = 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,9 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET users listing. */ | ||
router.get('/', function(req, res, next) { | ||
res.send('respond with a resource /users'); | ||
}); | ||
|
||
module.exports = 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,32 @@ | ||
{ | ||
"name": "base2-examples", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"1": "./node_modules/.bin/nodemon helloworld/app.js", | ||
"2": "./node_modules/.bin/nodemon mount-routes/app.js", | ||
"3": "./node_modules/.bin/nodemon views-jade/app.js", | ||
"4": "./node_modules/.bin/nodemon static-server/app.js", | ||
"5": "./node_modules/.bin/nodemon static-server2/app.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/i5ting/base2-examples.git" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/i5ting/base2-examples/issues" | ||
}, | ||
"homepage": "https://github.com/i5ting/base2-examples#readme", | ||
"dependencies": { | ||
"base2": "^1.0.10", | ||
"express": "^4.13.3", | ||
"jade": "^1.11.0" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.8.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,7 @@ | ||
var app = require('base2')({ | ||
// debug: true, | ||
root:__dirname, | ||
"public": "public", | ||
}) | ||
|
||
app.start(3029); |
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 @@ | ||
www |
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 @@ | ||
var app = require('base2')({ | ||
debug: true, | ||
root:__dirname, | ||
"routes": "routes", | ||
"views" : "views", | ||
"public": "public" | ||
}); | ||
|
||
app.start(3029); |
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 @@ | ||
www |
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 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET home page. */ | ||
router.get('/', function(req, res, next) { | ||
res.render('index', { title: 'Express' }); | ||
}); | ||
|
||
module.exports = 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,9 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET users listing. */ | ||
router.get('/', function(req, res, next) { | ||
res.send('respond with a resource /users'); | ||
}); | ||
|
||
module.exports = 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,6 @@ | ||
extends layout | ||
|
||
block content | ||
h1= message | ||
h2= error.status | ||
pre #{error.stack} |
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,5 @@ | ||
extends layout | ||
|
||
block content | ||
h1= title | ||
p Welcome to #{title} |
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,7 @@ | ||
doctype html | ||
html | ||
head | ||
title= title | ||
link(rel='stylesheet', href='/stylesheets/style.css') | ||
body | ||
block content |
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,8 @@ | ||
var app = require('base2')({ | ||
debug: true, | ||
root:__dirname, | ||
"routes": "routes", | ||
"views" : "views" | ||
}); | ||
|
||
app.start(3029); |
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 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET home page. */ | ||
router.get('/', function(req, res, next) { | ||
res.render('index', { title: 'Express' }); | ||
}); | ||
|
||
module.exports = 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,9 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
|
||
/* GET users listing. */ | ||
router.get('/', function(req, res, next) { | ||
res.send('respond with a resource /users'); | ||
}); | ||
|
||
module.exports = 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,6 @@ | ||
extends layout | ||
|
||
block content | ||
h1= message | ||
h2= error.status | ||
pre #{error.stack} |
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,5 @@ | ||
extends layout | ||
|
||
block content | ||
h1= title | ||
p Welcome to #{title} |
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,7 @@ | ||
doctype html | ||
html | ||
head | ||
title= title | ||
link(rel='stylesheet', href='/stylesheets/style.css') | ||
body | ||
block content |