Last active
June 26, 2019 15:26
-
-
Save 99darwin/a318fc471631b656be2e321c7bc79485 to your computer and use it in GitHub Desktop.
Simple server for node-rpc-tutorial
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
const express = require('express') | |
const bodyParser = require('body-parser') | |
const path = require('path') | |
const app = express() | |
const port = process.env.PORT || 1337 | |
app.use(bodyParser.json()) | |
app.use(bodyParser.urlencoded({ extended: true })) | |
app.use(bodyParser.text()) | |
app.use(bodyParser.json({ type: "application/vnd.api+json" })) | |
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") | |
next() | |
}) | |
app.use(express.static(path.join(__dirname, 'src'))) | |
require('./src/api')(app) | |
app.listen(port, () => { | |
console.log(`App listening on port: ${port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment