Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const app = express();
- const serveIndex = require('serve-index');
- // Error Handling
- app.use(function(err, req, res, next) {
- console.error(err.name + ": " + err.message);
- res.status(500).send("Error 500: Internal Server Error");
- });
- // Logging
- app.use(function(req, res, next) {
- console.log(req.method + ": '" + req.originalUrl + "'\t(" + req.ip + ")");
- next();
- });
- // Static Files
- app.use(express.static('public'));
- app.use(serveIndex('public', {
- icons: true,
- view: 'details',
- stylesheet: 'content/style.css',
- template: 'content/directory.html'
- }));
- // Error 404
- app.use(function(req, res, next) {
- console.warn("Error 404: '" + req.path + "'");
- res.status(404).send('Error 404: File Not Found');
- });
- app.listen(80, function() {
- console.log("Listening on port 80.");
- });
Advertisement
Add Comment
Please, Sign In to add comment