Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const http = require('http');
- const fs = require('fs');
- const path = require('path');
- const server = http.createServer((req, res) => {
- const filePath = path.join(__dirname, req.url);
- const ext = path.extname(filePath);
- if (ext === '.custom-file-type') {
- fs.readFile(filePath, (err, data) => {
- if (err) {
- res.writeHead(404, { 'Content-Type': 'text/plain' });
- res.end('File not found');
- } else {
- res.writeHead(200, { 'Content-Type': 'custom/filetype' });
- res.end(data);
- }
- });
- } else {
- // Handle other file types or routes
- }
- });
- server.listen(3000, () => {
- console.log('Server listening on port 3000');
- });
- const express = require('express');
- const fs = require('fs');
- const path = require('path');
- const app = express();
- app.use((req, res, next) => {
- const filePath = path.join(__dirname, req.url);
- const ext = path.extname(filePath);
- if (ext === '.testext') {
- fs.readFile(filePath, (err, data) => {
- if (err) {
- res.status(404).type('text/plain').send('File not found');
- } else {
- res.status(200).type('your-custom-mime-type').send(data);
- }
- });
- } else {
- next();
- }
- });
- app.listen(3000, () => {
- console.log('Server listening on port 3000');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement