我想运行一个非常简单的HTTP服务器.每个GET请求都example.com应该index.html提供给它,但作为常规HTML页面(即,与您阅读普通网页时相同的体验).
使用下面的代码,我可以阅读的内容index.html.我如何index.html作为常规网页?
var http = require('http');
var fs = require('fs');
var index = fs.readFileSync('index.html');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(index);
}).listen(9615);
Run Code Online (Sandbox Code Playgroud)
下面的一个建议很复杂,需要我为get我想要使用的每个资源(CSS,JavaScript,图像)文件写一行.
如何使用一些图像,CSS和JavaScript提供单个HTML页面?
我正在学习NodeJs:http://www.tutorialspoint.com/nodejs/
我无法理解使用http模块(get/post方法)与使用express模块(get/post方法)之间的区别
快递模块似乎很快就可以开发了.
谢谢
昨天我设法让我的API在我的本地计算机上工作,但是今天(相同的代码)在另一台计算机上,它不能正常工作,我在控制台上收到此错误:
无法加载http:// localhost:52056/api/task:'Access-Control-Allow-Origin'标头的值为'null',不等于提供的原点.因此不允许原点'null'访问.
以下是Chrome上的http请求和响应:
(我在IE/Firefox中看不到错误)
这是我的启动类(使用.net core 2)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using TodoApi;
namespace TestCors
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ITaskWarehouse, TaskWarehouse>();
services.AddCors();
services.AddMvc();
} …Run Code Online (Sandbox Code Playgroud)