Last active
August 29, 2015 14:10
-
-
Save yodarjun/31b457c05220c7cefcee to your computer and use it in GitHub Desktop.
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
'use strict'; | |
var express = require('express'); | |
var morgan = require('morgan'); | |
var chalk = require('chalk'); | |
var app = express(); | |
var PORT = 8200; | |
// Log all requests | |
app.use(morgan('dev')); | |
// Set CORS headers for all requests | |
app.use(function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, application"); | |
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS"); | |
next(); | |
}); | |
app.post('/api/user', function(req, res) { | |
var user = { | |
age: '30', | |
ethnicity: 'asian', | |
first_name: 'Arjun', | |
gender: 'Male', | |
last_name: 'Anand', | |
tags: ['foo', 'bar'] | |
}; | |
res.json(user); | |
}); | |
app.listen(PORT); | |
console.log( | |
'[' + chalk.yellow('express') + ']' + | |
chalk.yellow(' listening on port ') + | |
chalk.green(PORT) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment