Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const path = require('path');
- const url = require('url');
- function getContentType(url) {
- //
- }
- module.exports = (req, res) => {
- req.pathname = req.pathname || url.parse(req.url).pathname;
- if(req.pathname.startsWith('/content/') && req.method === 'GET') {
- let filePath = path.normalize(path.join(__dirname, `..${req.pathname}`));
- fs.readFile(filePath, (err, data => {
- if(err) {
- res.WriteHead(404, {
- 'Content-Type': 'text/plain'
- });
- }
- res.write('Resource not found!');
- res.end();
- return;
- }
- res.writeHead(200, {
- 'Content-Type': getContentType(req.pathname)
- });
- ));
- } else {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement