Created
August 31, 2015 15:11
-
-
Save romain-h/16d4495face8e18bce28 to your computer and use it in GitHub Desktop.
Simple ES6 node endpoint
This file contains hidden or 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
import express from 'express'; | |
import logger from 'morgan'; | |
import bodyParser from 'body-parser'; | |
let app = express(); | |
app.use(logger('dev')); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded()); | |
// Cors | |
app.all('*', (req, res, next) => { | |
res.header('Access-Control-Allow-Origin', '*'); | |
res.header('Access-Control-Allow-Headers', 'X-Requested-With'); | |
res.header('Access-Control-Allow-Credentials', true); | |
next(); | |
}); | |
app.get('/', (req, res) => { | |
res.json({message: 'ok'}); | |
}); | |
export default app; |
This file contains hidden or 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
{ | |
"name": "Simple server", | |
"version": "1.0.0", | |
"description": "", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node server.js" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"babel": "^5.8.23", | |
"body-parser": "^1.13.3", | |
"express": "^4.13.3", | |
"morgan": "^1.6.1" | |
} | |
} |
This file contains hidden or 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
require('babel/register'); | |
var app = require('./main'); | |
var PORT = 9003; | |
app.listen(PORT, function () { | |
console.log('Simple server listening on %d', PORT); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment