0.0.1 • Published 5 years ago
sfr-raw-body v0.0.1
Simple, Fast, Reliable(SFR)
sfr-raw-body
A body parser for sfr, base on formidable.
npm i sfr-raw-body
Usage
'use strict';
const sfr = require('sfr');
const sfrRqwBody = require('sfr-raw-body');
const app = new sfr({
serverType: 'http'
});
app.use(sfrRqwBody());
app.use(async (ctx, next) => {
if (ctx.req.url == '/upload' && ctx.req.method.toLowerCase() == 'post') {
ctx.res.setHeader('content-type', 'application/json');
ctx.body = JSON.stringify({
title: ctx.req.fields.title
});
return
}
if (ctx.req.url == '/upload' && ctx.req.method.toLowerCase() == 'get') {
ctx.res.setHeader('content-type', 'text/html');
ctx.body =
'<form action="/upload" enctype="multipart/form-data" method="post">' +
'<input type="text" name="title"><br>' +
'<input type="file" name="upload" multiple="multiple"><br>' +
'<input type="submit" value="Upload">' +
'</form>';
}
ctx.res.statusCode = 404;
ctx.body = 'not found.';
await next();
});
app.start();
Copyright (C) 2019 Jkin.feng. Licensed MIT. For more details, please see LICENSE.
0.0.1
5 years ago