Note that there are some explanatory texts on larger screens.

plurals
  1. POAngular Seed project, set index.html by default
    primarykey
    data
    text
    <p>I am using the <a href="https://github.com/angular/angular-seed" rel="nofollow noreferrer">Angular Seed project</a> to build a simple website. When i start the node server and enter the url at localhost:8000, it serves up the directory contents. I would like it to serve up the index.html file but would like to do this without a redirect. </p> <p>I believe that I need to modify the following function and that I should change the code for the <code>isDirectory</code> check but I'm not sure if that is the correct way to go about doing this. Any suggestions would be appreciated.</p> <pre><code>StaticServlet.prototype.handleRequest = function(req, res) { var self = this; var path = ('./' + req.url.pathname).replace('//','/').replace(/%(..)/g, function(match, hex){ return String.fromCharCode(parseInt(hex, 16)); }); var parts = path.split('/'); if (parts[parts.length-1].charAt(0) === '.') return self.sendForbidden_(req, res, path); fs.stat(path, function(err, stat) { if (err) return self.sendMissing_(req, res, path); if (stat.isDirectory()) return self.sendDirectory_(req, res, path); return self.sendFile_(req, res, path); }); } </code></pre> <hr> <p><strong>Update #1</strong></p> <p>I have two screenshots to clarify. The first image is what I currently get, the second image is what I want. </p> <p><strong>What I Get</strong> <img src="https://i.imgur.com/C7ISpOR.png" alt="What I Get"></p> <hr> <p><strong>What I Want</strong> <img src="https://i.stack.imgur.com/fEtVV.png" alt="What I Want"></p> <hr> <p><strong>Update #2</strong></p> <p>Using the link to Restify below I found the following example which is exactly what I needed.</p> <pre><code>var server = restify.createServer(); var io = socketio.listen(server); server.get('/', function indexHTML(req, res, next) { fs.readFile(__dirname + '/index.html', function (err, data) { if (err) { next(err); return; } res.setHeader('Content-Type', 'text/html'); res.writeHead(200); res.end(data); next(); }); io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); }); server.listen(8080, function () { console.log('socket.io server listening at %s', server.url); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload