2
* Copyright 2016 Google Inc. All rights reserved.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
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.
24
var path = require('path');
25
var express = require('express');
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', '/');
37
// Allow all assets in the project to be served (This includes sw-toolbox.js)
38
app.use('/', express.static(path.join(__dirname, '..', '..')));
40
// If the user tries to go to the root of the test server, redirect them
42
app.get('/', function(req, res) {
43
res.redirect('/test/');
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'));
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);