OpenShift node.js app writes all output to HTML body as a string

I'm creating a node.js app in OpenShift and I have a bizarre issue where everything that I write() is being displayed in the body of the response as a string. For example, when a request is made for the login page, this is what appears as a result:

<!DOCTYPE html>
<html>

<head>

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="style.css">

  etc...

If I inspect the response in Chrome, this is what it shows:

http://i.imgur.com/ggUgdQt.png

As you can see, all of my output is being sent as a string inside the html body. All of my code works fine on my development environment and pages are sent and displayed correctly, it's just OpenShift that does this. I'm using the connect library and reading and writing files as you would expect -- for the above case this would be the code being run:

var http = require('http');
var https = require('https');
var fs = require('fs');
var URL = require('url');
var mysql = require('mysql');
var cookies = require('cookies');
var request = require('request');
var bcrypt = require('bcrypt');
var connect = require('connect');
var bodyParser = require('body-parser');

// Setup Connect
var app = connect();
app.use(bodyParser.urlencoded( { extended : true } ));

// Set up mysql connection
var connection = mysql.createConnection({
  host          : process.env.OPENSHIFT_MYSQL_DB_HOST,
  user          : process.env.OPENSHIFT_MYSQL_DB_USERNAME,
  password  : process.env.OPENSHIFT_MYSQL_DB_PASSWORD,
  port          : process.env.OPENSHIFT_MYSQL_DB_PORT,
});
connection.connect();

console.log("Starting server...");

// Main request handler
app.use(function (req, res) {
    var url = URL.parse(req.url, true);
    var pathname = url.pathname;
    console.log("Request for " + pathname);

    ...

    if(pathname === "/") {
        loginForm(req, res);
    }

    ...

}

http.createServer(app).listen(process.env.OPENSHIFT_NODEJS_PORT, process.env.OPENSHIFT_NODEJS_IP);

console.log("Server ready.");

function loginForm(req, res) {
  fs.readFile('client/login.html', function(err, file) {
    if(err) {  
      res.writeHead(500, {"Content-Type": "text/plain"});
      res.write(err + "\n");
      res.end();
      return;
    }

    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.write(file);
    res.end();
  });
}

I had the same issue, change,

res.writeHead(200, {'Content-Type': 'text/plain'});

to

res.writeHead(200, {'Content-Type': 'text/html'});

The same for the 500 http code, Content-Type should be text/html.