Showing
1 changed file
with
9 additions
and
1 deletions
1 | const express = require('express'); | 1 | const express = require('express'); |
2 | const app = express(); | 2 | const app = express(); |
3 | -// const cors = require('cors'); | 3 | +const cors = require('cors'); |
4 | const port = 8000; | 4 | const port = 8000; |
5 | 5 | ||
6 | const mongoose = require('mongoose'); | 6 | const mongoose = require('mongoose'); |
... | @@ -9,6 +9,14 @@ const bodyParser = require('body-parser'); | ... | @@ -9,6 +9,14 @@ const bodyParser = require('body-parser'); |
9 | app.use(bodyParser.urlencoded({extended:true})); | 9 | app.use(bodyParser.urlencoded({extended:true})); |
10 | app.use(bodyParser.json()); | 10 | app.use(bodyParser.json()); |
11 | 11 | ||
12 | +// app.all('/*', function(req, res, next){ | ||
13 | +// res.header("Access-Control-Allow-Origin", "*"); | ||
14 | +// res.header("Access-Control-Allow-Headers", "X-Requested-With"); | ||
15 | +// next(); | ||
16 | +// }) | ||
17 | + | ||
18 | +app.use(cors()); | ||
19 | + | ||
12 | const db = mongoose.connection; | 20 | const db = mongoose.connection; |
13 | db.on('error', console.error); | 21 | db.on('error', console.error); |
14 | db.once('open', function(){ | 22 | db.once('open', function(){ | ... | ... |
-
Please register or login to post a comment