Skip to content

Commit bb0f319

Browse files
committed
test(server): handle route by route, load sample json data
1 parent a9a1816 commit bb0f319

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

test/data/customer.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
3+
}

test/data/store.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "Demo store"
3+
}

test/server.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict'
2+
3+
// load the lib object
4+
const { welcome } = require('./../src/')
5+
// sample JSON data
6+
const store = require('./data/store.json')
7+
const customer = require('./data/customer.json')
8+
// setup dev server with BrowserSync
9+
const browserSync = require('browser-sync').create()
10+
11+
browserSync.init({
12+
server: './test/',
13+
middleware: [
14+
{
15+
route: '/welcome',
16+
handle (req, res, next) {
17+
welcome(store, customer)
18+
.then(html => res.end(html))
19+
.catch(err => console.error(err))
20+
}
21+
}
22+
],
23+
24+
// watch template source files and reload local server
25+
watch: true,
26+
files: [ 'views/*.ejs', 'scss/*.scss', 'i18n/*.json' ]
27+
})

0 commit comments

Comments
 (0)