Last active
November 28, 2019 06:55
-
-
Save crookse/a0fa0115251ee3fb1fd7004bba5f5741 to your computer and use it in GitHub Desktop.
Vue: Automate Your Routing - index.js (index.html)
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 http = require('http'); | |
const fs = require('fs'); | |
let server = http.createServer((req, res) => { | |
// If the request is for an asset, then send the asset and end the response | |
if (req.url.includes('assets/')) { | |
res.write(fs.readFileSync(`${__dirname}/${req.url}`)); | |
return res.end(); | |
} | |
// Tell the client (the browser in our case) we are sending a `text/html` document | |
res.setHeader('Content-Type', 'text/html'); | |
// Write the contents of our `index.html` file to the response's body | |
res.write(fs.readFileSync('./index.html')); | |
// End the response | |
return res.end(); | |
}); | |
// Start at localhost:3000 | |
server.listen(3000, 'localhost', () => { | |
console.log('Server stared at localhost:3000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment