Browse Source

CORS

master
Lloyd Brookes 9 years ago
parent
commit
28018c32c0
  1. 4
      lib/local-web-server.js
  2. 0
      test/fixture/.local-web-server.json
  3. 4
      test/fixture/ajax.html
  4. 0
      test/fixture/big-file.txt
  5. 0
      test/fixture/file.txt
  6. 0
      test/fixture/something.php
  7. 8
      test/test.js

4
lib/local-web-server.js

@ -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) => {

0
test/static/.local-web-server.json → test/fixture/.local-web-server.json

4
test/ajax.html → test/fixture/ajax.html

@ -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>

0
test/static/big-file.txt → test/fixture/big-file.txt

0
test/static/file.txt → test/fixture/file.txt

0
test/static/something.php → test/fixture/something.php

8
test/test.js

@ -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 => {

Loading…
Cancel
Save