Skip to content

Commit 8cff92d

Browse files
committed
1. Miscellaneous fixes to Express's Response class
2. Added a setContentType method to Http's ServerResponse class 3. Added ServerOptions (to support SSL) to MongoDB module
1 parent 57350d9 commit 8cff92d

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed

node/http/src/main/scala/org/scalajs/nodejs/http/ServerResponse.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.scalajs.nodejs.http
22

33
import org.scalajs.nodejs.events.EventEmitter
44
import org.scalajs.nodejs.stream.Writable
5-
import org.scalajs.nodejs.events.EventEmitter
65

76
import scala.scalajs.js
87

@@ -146,6 +145,17 @@ object ServerResponse {
146145
*/
147146
implicit class ServerResponseExtensions(val response: ServerResponse) extends AnyVal {
148147

148+
/**
149+
* Sets the content-type for the response
150+
* @param contentType the given MIME type
151+
*/
152+
@inline
153+
def setContentType(contentType: String) = response.setHeader("Content-Type", contentType)
154+
155+
/////////////////////////////////////////////////////////////////////////////////
156+
// Response Shortcuts
157+
/////////////////////////////////////////////////////////////////////////////////
158+
149159
@inline
150160
def badRequest() = response.sendStatus(400)
151161

node_libs/express/src/main/scala/org/scalajs/nodejs/express/Application.scala

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import org.scalajs.nodejs.errors
44
import org.scalajs.nodejs.events.EventEmitter
55
import org.scalajs.nodejs.http.Server
66
import org.scalajs.nodejs.util.ScalaJsHelper._
7-
import org.scalajs.nodejs.events.EventEmitter
8-
import org.scalajs.nodejs.http.Server
9-
import org.scalajs.nodejs.util.ScalaJsHelper
107

118
import scala.scalajs.js
9+
import scala.scalajs.js.|
1210

1311
/**
1412
* The app object conventionally denotes the Express application. Create it by calling the
@@ -92,31 +90,31 @@ trait Application extends Router with EventEmitter {
9290
* This method is identical to Node’s http.Server.listen().
9391
* @example app.listen(port, [hostname], [backlog], [callback])
9492
*/
95-
def listen(port: Int, hostname: String, backlog: Int, callback: js.Function): Unit = js.native
93+
def listen(port: Int | String, hostname: String, backlog: Int, callback: js.Function): Unit = js.native
9694

9795
/**
9896
* Binds and listens for connections on the specified host and port.
9997
* This method is identical to Node’s http.Server.listen().
10098
*/
101-
def listen(port: Int, hostname: String, backlog: Int): Unit = js.native
99+
def listen(port: Int | String, hostname: String, backlog: Int): Unit = js.native
102100

103101
/**
104102
* Binds and listens for connections on the specified host and port.
105103
* This method is identical to Node’s http.Server.listen().
106104
*/
107-
def listen(port: Int, hostname: String, callback: js.Function): Unit = js.native
105+
def listen(port: Int | String, hostname: String, callback: js.Function): Unit = js.native
108106

109107
/**
110108
* Binds and listens for connections on the specified host and port.
111109
* This method is identical to Node’s http.Server.listen().
112110
*/
113-
def listen(port: Int, hostname: String): Unit = js.native
111+
def listen(port: Int | String, hostname: String): Unit = js.native
114112

115113
/**
116114
* Binds and listens for connections on the specified host and port.
117115
* This method is identical to Node’s http.Server.listen().
118116
*/
119-
def listen(port: Int, callback: js.Function): Server = js.native
117+
def listen(port: Int | String, callback: js.Function): Server = js.native
120118

121119
/**
122120
* Binds and listens for connections on the specified host and port.
@@ -201,17 +199,17 @@ object Application {
201199
/**
202200
* Binds and listens for connections on the specified host and port.
203201
*/
204-
def listenFuture(port: Int) = futureCallbackE1[errors.Error, Server](app.listen(port, _))
202+
def listenFuture(port: Int | String) = futureCallbackE1[errors.Error, Server](app.listen(port, _))
205203

206204
/**
207205
* Binds and listens for connections on the specified host and port.
208206
*/
209-
def listenFuture(port: Int, hostname: String) = futureCallbackE1[errors.Error, Server](app.listen(port, hostname, _))
207+
def listenFuture(port: Int | String, hostname: String) = futureCallbackE1[errors.Error, Server](app.listen(port, hostname, _))
210208

211209
/**
212210
* Binds and listens for connections on the specified host and port.
213211
*/
214-
def listenFuture(port: Int, hostname: String, backlog: Int) = futureCallbackE1[errors.Error, Server](app.listen(port, hostname, backlog, _))
212+
def listenFuture(port: Int | String, hostname: String, backlog: Int) = futureCallbackE1[errors.Error, Server](app.listen(port, hostname, backlog, _))
215213

216214
}
217215

node_libs/express/src/main/scala/org/scalajs/nodejs/express/Request.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.scalajs.nodejs.express
22

3-
import org.scalajs.nodejs.http.ClientRequest
43
import org.scalajs.nodejs.http.ClientRequest
54

65
import scala.scalajs.js
6+
import scala.scalajs.js.|
77

88
/**
99
* Express Http Request

node_libs/express/src/main/scala/org/scalajs/nodejs/express/Response.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.scalajs.nodejs.express
22

3-
import org.scalajs.nodejs.http.ServerResponse
43
import org.scalajs.nodejs.http.ServerResponse
54

65
import scala.scalajs.js
@@ -297,7 +296,10 @@ object Response {
297296
def internalServerError(message: String) = response.status(500).send(message)
298297

299298
@inline
300-
def internalServerError(cause: Throwable) = response.status(500).send(cause.getMessage)
299+
def internalServerError(cause: Throwable) = {
300+
cause.printStackTrace()
301+
response.status(500).send(cause.getMessage)
302+
}
301303

302304
@inline
303305
def notFound() = response.sendStatus(404)

node_libs/mongodb/src/main/scala/org/scalajs/nodejs/mongodb/ServerClass.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.scalajs.nodejs.mongodb
22

33
import org.scalajs.nodejs.util.ScalaJsHelper._
4-
import org.scalajs.nodejs.util.ScalaJsHelper
54

65
import scala.scalajs.js
76

@@ -34,7 +33,7 @@ object ServerClass {
3433
implicit class ServerClassExtensions(val `class`: ServerClass) extends AnyVal {
3534

3635
@inline
37-
def apply(host: String, port: Int) = `class`.New[Server](host, port)
36+
def apply(host: String, port: Int, options: ServerOptions = null) = `class`.New[Server](host, port, options)
3837

3938
}
4039

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.scalajs.nodejs.mongodb
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.ScalaJSDefined
5+
6+
/**
7+
* MongoDB Server Options
8+
9+
*/
10+
@ScalaJSDefined
11+
class ServerOptions(ssl: js.UndefOr[Boolean] = js.undefined) extends js.Object

0 commit comments

Comments
 (0)