-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
let express = require("express"); | ||
let app = express(); | ||
|
||
// Here, we will require the configuration files | ||
require("./config/static-files")(express, app); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Hello there!</h1> | ||
<p>If you can see this, the server is running and has been configured correctly.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env node | ||
let app = require("../app"); | ||
let http = require("http"); | ||
|
||
// Define a port for the server to listen on | ||
let port = process.env.PORT || 3000; | ||
app.set("port", port); | ||
|
||
// Create a server instance | ||
let server = http.createServer(app); | ||
|
||
// Make the server listen on a port | ||
server.listen(port); | ||
|
||
// Handle errors and success | ||
server.on("error", onError); | ||
server.on("listening", onListening); | ||
|
||
function pipeOrPort(address) { | ||
return typeof address == "string" ? `pipe ${address}` : `port ${address.port}`; | ||
} | ||
|
||
function onError(error) { | ||
if (error.syscall != "listen") { | ||
throw error; | ||
} | ||
|
||
let bind = pipeOrPort(server.address()); | ||
|
||
switch (error.code) { | ||
case "EACCES": | ||
console.error(`${bind} requires elevated privileges.`); | ||
process.exit(1); | ||
break; | ||
case "EADDRINUSE": | ||
console.error(`${bind} is already in use.`); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
function onListening() { | ||
let bind = pipeOrPort(server.address()); | ||
console.log(`Listening on ${bind}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function(express, app) { | ||
app.use("/assets", express.static("assets")); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"scripts": { | ||
"start": "node ./bin/www", | ||
} |