本文整理汇总了TypeScript中body-parser.text函数的典型用法代码示例。如果您正苦于以下问题:TypeScript text函数的具体用法?TypeScript text怎么用?TypeScript text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了text函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: runServer
function runServer(schemaIDL: Source, extensionIDL: Source, optionsCB) {
const app = express();
if (extensionIDL) {
const schema = buildServerSchema(schemaIDL);
extensionIDL.body = extensionIDL.body.replace('<RootTypeName>', schema.getQueryType().name);
}
app.options('/graphql', cors(corsOptions))
app.use('/graphql', cors(corsOptions), graphqlHTTP(() => {
const schema = buildServerSchema(schemaIDL);
return {
...optionsCB(schema, extensionIDL),
graphiql: true,
};
}));
app.get('/user-idl', (_, res) => {
res.status(200).json({
schemaIDL: schemaIDL.body,
extensionIDL: extensionIDL && extensionIDL.body,
});
});
app.use('/user-idl', bodyParser.text());
app.post('/user-idl', (req, res) => {
try {
if (extensionIDL === null)
schemaIDL = saveIDL(req.body);
else
extensionIDL = saveIDL(req.body);
res.status(200).send('ok');
} catch(err) {
res.status(500).send(err.message)
}
});
app.use('/editor', express.static(path.join(__dirname, 'editor')));
app.listen(argv.port);
log(`\n${chalk.green('â')} Your GraphQL Fake API is ready to use đ
Here are your links:
${chalk.blue('âŻ')} Interactive Editor:\t http://localhost:${argv.port}/editor
${chalk.blue('âŻ')} GraphQL API:\t http://localhost:${argv.port}/graphql
`);
if (!fileArg) {
log(chalk.yellow(`Default file ${chalk.magenta(fileName)} is used. ` +
`Specify [file] parameter to change.`));
}
if (argv.open) {
setTimeout(() => opn(`http://localhost:${argv.port}/editor`), 500);
}
}
开发者ID:codeaudit,项目名称:graphql-faker,代码行数:60,代码来源:index.ts
示例2: if
app.use((req: express.Request, res, next) => {
if (req.path === "/mid-text") {
bodyParser.text({ type: "*/*" })(req, res, next);
} else if (req.path === "/mid-buffer") {
bodyParser.raw({ type: "*/*" })(req, res, next);
} else if (req.path === "/mid-json") {
bodyParser.json({ type: "*/*" })(req, res, next);
} else {
next();
}
});
开发者ID:nkjm,项目名称:line-bot-sdk-nodejs,代码行数:11,代码来源:test-server.ts
示例3: serve
async serve(port, websockets: boolean = false): Promise<Object> {
var http = require("http");
var express = require("express");
var cookieParser = require("cookie-parser");
var bodyParser = require("body-parser");
var multer = require("multer"); // v1.0.5
var upload = multer(); // for parsing multipart/form-data
var requestLimit = this.getGlobalParams().requestLimit
? this.getGlobalParams().requestLimit
: "20mb";
var app = express();
app.use(cookieParser());
app.use(
bodyParser.text({
type: "text/plain"
})
);
app.use(
bodyParser.json({
limit: requestLimit
})
);
app.use(
bodyParser.urlencoded({
extended: true
})
);
app.use(upload.array("file"));
// Will lower the limit soon, we should have a library that handle multipart file
app.use(
bodyParser.raw({
type: "*/*",
limit: requestLimit
})
);
app.set("trust proxy", "loopback, 10.0.0.0/8");
app.use(this.handleRequest.bind(this));
this.serveStaticWebsite(express, app);
this._http = http.createServer(app).listen(port);
if (websockets) {
// Activate websocket
this.output("Activating socket.io");
this._io = require("socket.io")(this._http);
this.emit("Webda.Init.SocketIO", this._io);
}
this.serveIndex(express, app);
this.output("Server running at http://0.0.0.0:" + port);
return new Promise(() => {});
}
开发者ID:loopingz,项目名称:webda-shell,代码行数:54,代码来源:http.ts
示例4: createExpressTestServer
export async function createExpressTestServer(requestHandler: express.RequestHandler) {
let app = express();
app.use(bodyParser.json());
app.use(bodyParser.text());
app.post('/test', requestHandler);
let port = await (new Promise<number>((resolve, reject) => {
let server = app.listen(0, () => {
resolve(server.address().port);
});
}));
return port;
}
开发者ID:smphhh,项目名称:simple-typed-rpc,代码行数:16,代码来源:express_test_server.ts
示例5: require
import * as http from 'http';
import express = require('express');
import {
json,
raw,
text,
urlencoded,
} from 'body-parser';
const app = express();
app.use(json());
app.use(raw());
app.use(text());
app.use(urlencoded());
const jsonParser = app.use(json({
inflate: true,
limit: '100kb',
type: 'application/*',
verify: (
req: http.IncomingMessage,
res: http.ServerResponse,
buf: Buffer,
encoding: string
) => {
return true;
}
}));
app.use(jsonParser);
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:30,代码来源:body-parser-tests.ts
示例6: init
export function init(port: number, mode: string) {
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(bodyParser.text());
app.use(compression());
// DB Init
Init();
/**
* Dev Mode.
* @note Dev server will only give for you middleware.
*/
if (mode == 'dev') {
app.all('/*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
next();
});
routes.init(app);
let root = path.resolve(process.cwd());
let clientRoot = path.resolve(process.cwd(), './dist/dev/client');
app.use(express.static(root));
app.use(express.static(clientRoot));
var renderIndex = (req: express.Request, res: express.Response) => {
res.sendFile(path.resolve(__dirname, _clientDir + '/index.html'));
};
app.get('/*', renderIndex);
/**
* Api Routes for `Development`.
*/
}
else {
/**
* Prod Mode.
* @note Prod mod will give you static + middleware.
*/
/**
* Api Routes for `Production`.
*/
routes.init(app);
/**
* Static.
*/
app.use('/js', express.static(path.resolve(__dirname, _clientDir + '/js')));
app.use('/css', express.static(path.resolve(__dirname, _clientDir + '/css')));
app.use('/assets', express.static(path.resolve(__dirname, _clientDir + '/assets')));
/**
* Spa Res Sender.
* @param req {any}
* @param res {any}
*/
var renderIndex = function (req: express.Request, res: express.Response) {
res.sendFile(path.resolve(__dirname, _clientDir + '/index.html'));
};
/**
* Prevent server routing and use @ng2-router.
*/
app.get('/*', renderIndex);
}
this.server = http.createServer(app);
rtsIo.io = socketIo(this.server);
this.server.listen(port);
//add error handler
this.server.on("error", (error: any) => {
console.log("ERROR", error);
});
//start listening on port
this.server.on("listening", () => {
console.log('==> Listening on port %s. Open up http://localhost:%s/ in your browser.', port, port);
});
return server;
};
开发者ID:ovintu,项目名称:rts,代码行数:86,代码来源:index.ts
示例7: Promise
new Promise((resolve, _reject) => {
const server = http.createServer();
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.text());
app.use(helmet());
// HTTP
app.post("/", (req, res) => {
const useJSON = req.headers["content-type"].indexOf("application/json") >= 0;
try {
if (useJSON) {
const { input, env } = assertMessage(req.body, false) as MetaesMessage;
log("[Server: got message]", { input, env });
context.evaluate(
input,
value => res.send(JSON.stringify(value)),
error => res.status(400).send(JSON.stringify(error)),
env
);
} else {
context.evaluate(
req.body,
value => res.send(JSON.stringify(value)),
error => res.status(400).send(JSON.stringify(error))
);
}
} catch (e) {
const error = { message: Array.isArray(e) ? e.map(e => e.message) : e.message };
res.status(400).send(JSON.stringify(error));
}
});
// WS
const webSocketServer = new WebSocket.Server({ server });
webSocketServer.on("connection", connection => {
const clientContext: Context = {
evaluate: (input: Source, _c?: Continuation, _cerr?: ErrorContinuation, environment?: Environment) => {
log("[Server: in evaluate/environment", environment);
const message = {
input: typeof input === "function" ? input.toString() : input,
env: environmentToMessage(clientContext, mergeValues({}, environment))
};
log("[Server sending message]", JSON.stringify(message));
connection.send(JSON.stringify(assertMessage(message)));
}
};
connection.on("message", async message => {
let environment;
try {
const { input, env } = assertMessage(JSON.parse(message)) as MetaesMessage;
environment = env ? environmentFromMessage(clientContext, env) : { values: {} };
log("[Server: got raw message]:", message);
log("[Server: client environmentFromJSON]", environment);
const result = await evalAsPromise(context, input, environment);
log("[Server: result]", result);
clientContext.evaluate(
`c(result)`,
environment.values.c,
environment.values.cerr,
mergeValues({ result }, environment)
);
} catch (e) {
log("[Server: caught error]", e.message);
log("[Server: client environment]", environment);
log("[Server: client environmentToJSON]", environmentToMessage(clientContext, environment));
clientContext.evaluate(
`cerr(error)`,
null,
null,
mergeValues({ error: { message: (e.originalError || e).message } }, environment)
);
}
});
connection.on("error", e => console.log(e));
connection.on("close", () => log("[Server: closed ws connection with browser.]"));
});
server.on("request", app);
server.on("error", e => log("[Server: caught error]", e));
const callback = () => {
log("[Server: Listening on " + JSON.stringify(server.address()) + "]");
resolve(server);
};
port ? server.listen(port, callback) : server.listen(callback);
});
开发者ID:metaes,项目名称:metaes,代码行数:94,代码来源:server.ts
示例8: express
import express, {Express} from 'express';
import bodyParser from 'body-parser';
import {resolve} from 'path';
import * as config from './config';
const app: Express = express();
app.use(bodyParser.text());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// Allow CORS.
app.use((req, res, next) => {
res.header('Access-Control-Allow-Methods', 'GET, POST, DELETE');
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
next();
});
export function serveStatic(prefix: string, app: Express) {
app.use(prefix, express.static(resolve(__dirname, process.env.IS_BUNDLE ? './app' : './docs')));
}
export function configService(prefix: string, app: Express) {
app.get(`${prefix}/config`, (req, res) => res.json(config));
}
export default app;
开发者ID:get-focus,项目名称:focus-help-center,代码行数:27,代码来源:index.ts
示例9: express
// import express from './express';
import {HomeUiText, IHomeUiText} from './src/resources/home/HomeUiText';
import {Job, IJob} from './src/shared/models/Job';
import {ExperienceItem, IExperienceItem} from './src/shared/models/ExperienceItem';
import {TechnologyType} from './src/shared/models/Enums'
var app: any = express();
var homeUiText = new HomeUiText();
app.use(express.static('./src/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.text({ type: 'text/html'}));
app.use(cookieParser('JrSecret7'));
app.use(cookieSession({
name: 'session',
keys: ['key1', 'key2']
}))
app.set('view engine', 'ejs');
app.set('views', './src/server/views/pages');
var Routes = {
Home: '/',
CV: '/cv/',
LiveChat: '/livechat',
Assessment: '/assessment',
UnitTests: '/tests',
开发者ID:JustinRickard,项目名称:CV,代码行数:29,代码来源:ServerApp.ts
示例10: init
export async function init(port: string, mode: string) {
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(bodyParser.text());
app.use(compression());
// DB Init
Init();
/**
* Dev Mode.
* @note Dev server will only give for you middleware.
*/
if (mode === 'dev') {
app.all('/*', (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
next();
});
routes.init(app);
const root = path.resolve(process.cwd());
const clientRoot = path.resolve(process.cwd(), './dist/client/dev');
app.use(express.static(root));
app.use(express.static(clientRoot));
const renderIndex = (req: express.Request, res: express.Response) => {
res.sendFile(path.resolve(__dirname, _clientDir + '/index.html'));
};
app.get('/*', renderIndex);
/**
* Api Routes for `Development`.
*/
} else {
/**
* Prod Mode.
* @note Prod mod will give you static + middleware.
*/
/**
* Api Routes for `Production`.
*/
routes.init(app);
/**
* Client Dir
*/
_clientDir = '../../client/prod';
/**
* Static.
*/
app.use('/js', express.static(path.resolve(__dirname, _clientDir + '/js')));
app.use('/css', express.static(path.resolve(__dirname, _clientDir + '/css')));
app.use('/assets', express.static(path.resolve(__dirname, _clientDir + '/assets')));
/**
* Spa Res Sender.
* @param req {any}
* @param res {any}
*/
const renderIndex = (req: express.Request, res: express.Response) => {
res.sendFile(path.resolve(__dirname, _clientDir + '/index.html'));
};
/**
* Prevent server routing and use @ng2-router.
*/
app.get('/*', renderIndex);
}
/**
* Server with gzip compression.
*/
const server: any = await app.listen(port);
const serverPort: string = server.address().port;
console.log(`App is listening on port: ${serverPort}`);
}
开发者ID:vyakymenko,项目名称:angular2-seed-express,代码行数:83,代码来源:index.ts
注:本文中的body-parser.text函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论