Last active
September 5, 2019 10:08
-
-
Save feedsbrain/03c74178b6f0b5369b6a046373e4a7a0 to your computer and use it in GitHub Desktop.
Angular 2
This file contains 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
const express = require('express') | |
const path = require('path') | |
const fs = require('fs') | |
const app = express() | |
const staticRoot = path.resolve() // this is you app root | |
app.set('port', process.env.PORT || 3000) | |
app.use(express.static(staticRoot)) | |
app.use(function (req, res, next) { | |
// if the request is not html then move along | |
const accept = req.accepts('html', 'json', 'xml') | |
if (accept !== 'html') { | |
return next() | |
} | |
// if the request has a '.' assume that it's for a file, move along | |
const ext = path.extname(req.path) | |
if (ext !== '') { | |
return next() | |
} | |
fs.createReadStream(staticRoot + 'index.html').pipe(res) | |
}) | |
app.listen(app.get('port'), function () { | |
console.log('app running on port', app.get('port')) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment