Skip to content

Instantly share code, notes, and snippets.

@niftydevelopment
Created October 29, 2018 11:26
Show Gist options
  • Save niftydevelopment/b966fa0ed26604c54358424f7fe12b18 to your computer and use it in GitHub Desktop.
Save niftydevelopment/b966fa0ed26604c54358424f7fe12b18 to your computer and use it in GitHub Desktop.
En enkel webbserver.
var express = require("express");
var app = express();
/* serves main page */
app.get("/", function(req, res) {
//res.sendfile('index_es5.html')
res.sendfile('index.html')
});
app.post("/user/add", function(req, res) {
/* some server side logic */
res.send("OK");
});
/* serves all the static files */
app.get(/^(.+)$/, function(req, res){
console.log('static file request : ' + req.params);
res.sendfile( __dirname + req.params[0]);
});
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log("Listening on " + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment