Created
January 16, 2017 12:57
-
-
Save andreban/30d1624f3933ff06343d58ba2a84fe4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2015-2016, Google, Inc. | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
const express = require('express'); | |
const app = express(); | |
const useragent = require('useragent'); | |
const BASE_FILE_PATH = __dirname + '/public'; | |
app.get('/articles/article-:id.html', (req, res) => { | |
if (useragent.is(req.headers['user-agent']).safari && req.query.shell !== 'false') { | |
// Serve appshell | |
res.sendFile(BASE_FILE_PATH + '/shell.html'); | |
} else { | |
// Serve AMP! | |
res.sendFile(BASE_FILE_PATH + '/articles/article-' + req.params.id + '.html'); | |
} | |
}); | |
app.use(express.static('public')); | |
const port = process.env.PORT || 3000; | |
app.listen(port, () => { | |
console.log('Example app listening on port 3000!') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment