const express = require('express'); const http = require('http'); const cors = require('cors'); const app = express(); const PORT = 5500; // app.use((req, res, next) => {// res.header(' access-control-allow-origin ', '*') // res.header('Access-Control-Allow-Headers', 'Authorization,X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method' ) // res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PATCH, PUT, DELETE') // res.header('Allow', 'GET, POST, PATCH, OPTIONS, PUT, DELETE') // next(); / /}); // Allow cross-domain app.use(cors()); app.get('/', (req, res) => { res.send('Hello'); }); App. Get ('/city, (the req, res) = > {res. Json ({city: 'Shanghai'}); }); http.createServer(app).listen(PORT, () => { console.log(`Server is running on port: http://localhost:${PORT}`); });Copy the code