几天前我一直在寻找解决方案...所以基本上我有两个文件: index.html和hellonode.js。Index.html有一个带有文本的div和一个按钮,该按钮在单击时会向hellonode.js发出请求。hellonode.js应该接收请求并向它们发送响应。
hellonode.js:
var http= require('http');
function onRequest(request, response){
console.log("request has been received");
response.writeHead(20
下面是我用typescript编写的一个简单的express-server的代码。
import express from 'express';
import bodyParser from 'body-parser';
import path from 'path';
import fs from 'fs';
import { DISTDIR } from './shared/constants';
import LoginController from './controllers/login'
我理解客户端的HTTP请求是什么样子,但我好奇的是,服务器使用什么方法来为页面返回服务?
客户端:
GET /index.html HTTP/1.1
Host foo.com:80
服务器:
Does it perform an HTTP PUT of index.html ? If not, then what? Are HTTP methods used both ways?
如果响应不使用HTTP方法,那么包含有效负载的是一个TCP数据包(或多个)吗?数据包中是否有HTTP协议特定的信息?
我想访问由cms制作的html文件中的脚本标记的数据。有没有可能在不污染全局命名空间的情况下做到这一点?我尝试过使用es6模块,但是我失败了,而且我找不到任何关于它的信息。
<script>
let list = ['a','b','c'];
export default list
</script>
//test.js
import list from './index.html'
错误:' net::ERR_ABORTED 404
我开始使用nodejs了。到目前为止,我可以使用app.js节点应用程序打开网页index.html。
来自的示例:
//step 1) require the modules we need
var
http = require('http'),//helps with http methods
path = require('path'),//helps with file paths
fs = require('fs');//helps with file system tasks
//a helper function to handl
我正在开发一个Express应用程序,我想捕捉所有的路线并将用户重定向到/public/app/index.html
app.all('/*', function (req, res, next) {
// Just send the index.html for other files to support HTML5Mode
res.sendFile('/public/app/index.html', { root: __dirname });
});
但是当我运行服务器时,它会显示在屏幕上:
========================