Skip to content

Instantly share code, notes, and snippets.

@yodarjun
Last active August 29, 2015 14:10
Show Gist options
  • Save yodarjun/31b457c05220c7cefcee to your computer and use it in GitHub Desktop.
Save yodarjun/31b457c05220c7cefcee to your computer and use it in GitHub Desktop.
'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