~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/sw-toolbox/test/server/index.js

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2016 Google Inc. All rights reserved.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 *
 
16
 */
 
17
 
 
18
'use strict';
 
19
 
 
20
// This server is needed most importantly to add the Service-Worker-Allowed
 
21
// header to any service worker loaded in the tests. This allows the scope
 
22
// to be manipulated any way we want / need during testing.
 
23
 
 
24
var path = require('path');
 
25
var express = require('express');
 
26
var app = express();
 
27
 
 
28
// Set up static assets
 
29
app.use('/test/browser-tests/',
 
30
  express.static(path.join(__dirname, '..', 'browser-tests/'), {
 
31
    setHeaders: function(res) {
 
32
      res.setHeader('Service-Worker-Allowed', '/');
 
33
    }
 
34
  })
 
35
);
 
36
 
 
37
// Allow all assets in the project to be served (This includes sw-toolbox.js)
 
38
app.use('/', express.static(path.join(__dirname, '..', '..')));
 
39
 
 
40
// If the user tries to go to the root of the test server, redirect them
 
41
// to /test/
 
42
app.get('/', function(req, res) {
 
43
  res.redirect('/test/');
 
44
});
 
45
 
 
46
// Iframes need to have a page loaded so the service worker will have
 
47
// a page to claim and control. This is done by returning a basic
 
48
// html file for /test/iframe/<timestamp>
 
49
app.get('/test/iframe/:timestamp', function(req, res) {
 
50
  res.sendFile(path.join(__dirname, '..', 'data', 'test-iframe.html'));
 
51
});
 
52
 
 
53
// Start service on port 8888
 
54
var server = app.listen(8888, function() {
 
55
  console.log('Example app listening at http://localhost:%s',
 
56
    server.address().port);
 
57
});