Created
August 17, 2017 13:23
-
-
Save corysimmons/c6b31bc7d5d9d970d884175a293d8a0d to your computer and use it in GitHub Desktop.
nodemon + BrowserSync
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
</head> | |
<body> | |
<pre></pre> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<script> | |
axios | |
.get('http://localhost:1337') | |
.then(res => { | |
document.querySelector('pre').textContent = JSON.stringify(res.data, null, 2) | |
}) | |
.catch(err => console.error(err)) | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
{ | |
"scripts": { | |
"dev": "npm-run-all -p nodemon browser-sync", | |
"nodemon": "nodemon server.js", | |
"browser-sync": "browser-sync start -s --files=server.js --no-open --no-notify --reload-delay=500" | |
}, | |
"devDependencies": { | |
"npm-run-all": "^4.0.2" | |
}, | |
"dependencies": { | |
"browser-sync": "^2.18.13", | |
"kcors": "^2.2.1", | |
"koa": "^2.3.0", | |
"koa-router": "^7.1.1", | |
"nodemon": "^1.11.0" | |
} | |
} |
This file contains hidden or 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
const Koa = require('koa') | |
const Router = require('koa-router') | |
const cors = require('kcors') | |
const app = new Koa() | |
const router = new Router() | |
router.get(`/`, ctx => { | |
ctx.body = { | |
dogs: [`Fido`, `Rover`] | |
} | |
}) | |
app | |
.use(cors()) | |
.use(router.routes()) | |
.use(router.allowedMethods()) | |
app.listen(1337, () => console.log(`Koa at: http://localhost:1337`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment