如何使用Express或HTTP从其他服务器访问网站内容
我的网站包含所有数据,例如模板网站
我还有3个网站可以访问这个网站模板内容HTML CSS网站内的所有内容2 3和4唯一的defriend就是这样的路线
mysite.com/template1/的用户1 /index.html
mysite.com/template1/的用户2 /index.html
mysite.com/template1/的用户3 /index.html
我想要内部网站**(n)*只有从模板服务器获取HTML CSS和js内容的代码我是如何做到的?
在PHP中就像是
$url = $GET(www.masterserve.com/template1/ + user1 ) echo $url
我可以使用node.js和express
执行相同的任何示例// Get dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
// Get our API routes
const api = require('./server/routes/api');
const app = express();
// Parsers for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist'))); <-- idont want static
file only a URL from the master server
// Set our api routes
app.use('/api', api);
// Catch all other routes and return the index file
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '3000';
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on localhost:${port}`));
答案 0 :(得分:1)
如果您尝试从nodejs应用中获取其他服务器的HTTP内容,则可以使用request
module.
request.get('http://somesite.com/template1/user3/index.html', function(err, response, body) {
// access data from other web site here
});
如果您尝试将该数据流式传输到其他响应,您还可以.pipe()
将您请求的数据public func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
if textField.text!.isEmpty {
textField.text = "0.00"
}
let range2 = string.rangeOfCharacterFromSet(NSMutableCharacterSet.decimalDigitCharacterSet())
if range2 != nil{
// textField.text = "M"
var f = textField.text?.floatValue
f=f!*10.0
f=f!+(string.floatValue/100.0)
textField.text = NSString(format: "%.2f", f!) as String
return false;
}
var f = textField.text?.floatValue
f=f!/10.0
textField.text = NSString(format: "%.2f", f!) as String
return false;
}
发送给其他响应。该模块的文档显示了许多如何执行此操作的示例。