You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.1 KiB

9 years ago
  1. 'use strict'
  2. const test = require('tape')
  3. const request = require('req-then')
  4. const LocalWebServer = require('../../')
  5. const c = require('../common')
  6. test('spa', function (t) {
  7. t.plan(6)
  8. const ws = new LocalWebServer()
  9. ws.addSpa('one.txt')
  10. ws.addStatic(__dirname)
  11. const server = ws.getServer()
  12. server.listen(8100, () => {
  13. request('http://localhost:8100/asdf', { headers: { accept: 'text/html' } })
  14. .then(c.checkResponse(t, 200, /one/))
  15. /* html requests for missing files with extensions do not redirect to spa */
  16. .then(() => request('http://localhost:8100/asdf.txt', { headers: { accept: 'text/html' } }))
  17. .then(c.checkResponse(t, 404))
  18. /* existing static file */
  19. .then(() => request('http://localhost:8100/two.txt'))
  20. .then(c.checkResponse(t, 200, /two/))
  21. /* not a text/html request - does not redirect to spa */
  22. .then(() => request('http://localhost:8100/asdf', { headers: { accept: 'application/json' } }))
  23. .then(c.checkResponse(t, 404))
  24. .then(server.close.bind(server))
  25. .catch(c.fail(t))
  26. })
  27. })