This commit is contained in:
Lloyd Brookes
2015-11-13 11:42:16 +00:00
parent 69db357661
commit 28018c32c0
7 changed files with 9 additions and 7 deletions

View File

@ -7,6 +7,7 @@ const serveIndex = require('koa-serve-index')
const morgan = require('koa-morgan')
const compress = require('koa-compress')
const streamLogStats = require('stream-log-stats')
const cors = require('kcors')
/**
* @module local-web-server
@ -31,7 +32,8 @@ function getApp (options) {
const app = new Koa()
// CORS
/* CORS: allow from any origin */
app.use(convert(cors()))
if (options.mime) {
app.use((ctx, next) => {

View File

@ -9,10 +9,10 @@
<script>
var $ = document.querySelector.bind(document);
var req = new XMLHttpRequest();
req.open("get", "http://localhost:8000/README.md", true);
req.open("get", "http://localhost:8000/big-file.txt", true);
req.onload = function(){
$("#readme").textContent = this.responseText;
}
req.send()
</script>
</body>
</body>

View File

@ -41,7 +41,7 @@ test('static', function (t) {
const app = localWebServer({
log: { format: 'none' },
static: {
root: __dirname + '/static',
root: __dirname + '/fixture',
options: {
index: 'file.txt'
}
@ -57,7 +57,7 @@ test('serve-index', function (t) {
const app = localWebServer({
log: { format: 'none' },
serveIndex: {
path: __dirname + '/static',
path: __dirname + '/fixture',
options: {
icons: true
}
@ -74,7 +74,7 @@ test('compress', function(t){
const app = localWebServer({
compress: true,
log: { format: 'none' },
static: { root: __dirname + '/static' }
static: { root: __dirname + '/fixture' }
})
launchServer(app, { headers: { 'Accept-Encoding': 'gzip' } }, '/big-file.txt', response => {
t.strictEqual(response.res.headers['content-encoding'], 'gzip')
@ -85,7 +85,7 @@ test('mime', function(t){
t.plan(1)
const app = localWebServer({
log: { format: 'none' },
static: { root: __dirname + '/static' },
static: { root: __dirname + '/fixture' },
mime: { 'text/plain': [ 'php' ]}
})
launchServer(app, null, '/something.php', response => {