1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| const express = require('express') const app = express() const path = require('path');
const router=require('./02-路由模块')
const parser = require('body-parser');
app.use(parser.urlencoded({ extended: false }))
app.use('/', express.static(__dirname + '/public'));
app.all('*', function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length,Authorization,Origin,Accept,X-Requested-With'); res.header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS.PUT,PATCH,DELETE'); res.header('X-Powered-By', '3.2.1'); res.header('Content-Type', 'application/json;charset=utf-8'); next(); });
app.use(router);
app.listen(8080, () => { console.log(`Example app listening on port http://localhost:8080`) })
|