Skip to content

Instantly share code, notes, and snippets.

@h3xxx
Forked from jeff-hager-dev/app.js
Last active August 29, 2015 14:11
Show Gist options
  • Save h3xxx/b7856bd7544e77b0d2cd to your computer and use it in GitHub Desktop.
Save h3xxx/b7856bd7544e77b0d2cd to your computer and use it in GitHub Desktop.
var express = require('express');
var fs = require('fs');
var path = require('path');
var port = 3005;
var staticDir = "staticFiles"
var app = express();
app.use(function (req, res, next) {
//NOTE (JNHager): NEVER DO THIS IN A PRODUCTION SYSTEM. STRICTLY FOR TESTING LOCALLY!!!!
//NOTE (JNHager): SERIOUSLY DON'T, GOD WILL KILL KITTENS IF YOU DO THIS IN A PRODUCTION SYSTEM
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
next();
});
app.get("/", function(req, res) {
res.status(200)
.send({message: "Dude, this is a server"});
});
app.post("/", function(req, res) {
res.status(200)
.send({message: "Dude, this is a server"});
});
/* Servers static files
=============================================================================*/
app.use('/staticfile', express.static(staticDir));
/* Starting the Server
=============================================================================*/
app.listen(port, function() {
console.log("Simple Server Listening on " + port);
});
{
"name": "simpleExpressServer",
"version": "1.0.0",
"description": "A simple express server used for testing calls or prototyping a api call",
"main": "app.js",
"dependencies": {
"express": "^4.10.6"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"nodejs",
"express",
"server",
"api"
],
"author": "J. Nolan Hager (JNHager)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment