var express = require('express'); var app = express(); var bodyParser = require('body-parser') app.post('/highway', bodyParser.json(), function (req, res) { var json = { } res.setHeader("Access-Control-Allow-Origin","*") res.json(json) }) app.get('/highway', bodyParser.json(), function (req, res) { var json = { } res.setHeader("Access-Control-Allow-Origin","*") res.json(json) }) //运行接口 app.listen('9000', function () { console.log('port start') })
cmd窗口打开,执行:node server.js
浏览器访问:
http://127.0.0.1:9100/highway 标签:node,function,http,跨域,res,app,json,var,highway From: https://www.cnblogs.com/gaoqifang/p/17117100.html