可以借助koa2-cors快速实现 const path = require('path') const Koa = require('koa') const koaStatic = require('koa-static') const bodyParser = require('koa-bodyparser') const router = require('./router') const cors = require('koa2-cors') const app = new Koa() const port = 9871 ...
/* 写一个RESTful接口 */ const Koa = require('koa') const Router = require('koa-router') const cors = require('@koa/cors') const koaBody = require('koa-body'); const app = new Koa() const router = new Router() router.post('/post', (ctx, next) => { const { body } = ct...
const Hapi = require('@hapi/hapi'); const server = Hapi.server({ port: 3000, routes: { cors: true, }, }); server.route({ method: 'GET', path: '/', handler: (request, h) => { return 'Hello, Hapi!'; }, }); async function start { await server.start; console.log(Server ...
项目初始化首先保证你的node环境已经就绪 1、创建项目文件夹 创建文件夹test,在文件夹中shift+右键 在此处运行命令行运行 npm init --y 2、 安装依赖 npm i koa koa-body koa-static koa-cors 创建服务 // server.js /* * 1、在项目文件中创建一个server.js文件 02 面试官:webpack原理都不会? 前一段...
const Hapi = require('@hapi/hapi'); const server = Hapi.server({ port: 3000, routes: { cors: true, }, }); server.route({ method: 'GET', path: '/', handler: (request, h) => { return 'Hello, Hapi!'; }, }); async function start { await server.start; console.log(Server ...
const Hapi = require('@hapi/hapi'); const server = Hapi.server({ port: 3000, routes: { cors: true, }, }); server.route({ method: 'GET', path: '/', handler: (request, h) => { return 'Hello, Hapi!'; }, }); async function start { await server.start; console.log(Server ...