我正在使用undertow
静态地为React单页应用程序提供服务。为了使客户端路由正常工作,我需要为服务器上不存在的路由返回相同的索引文件。 (有关问题click here的更好解释。)
当前使用以下ResourceHandler实现:
ResourceHandler(resourceManager, { exchange ->
val handler = FileErrorPageHandler({ _: HttpServerExchange -> }, Paths.get(config.publicResourcePath + "/index.html"), arrayOf(OK))
handler.handleRequest(exchange)
}).setDirectoryListingEnabled(false)
它可以工作,但是很老套。我觉得必须有一种更优雅的方式来实现这一目标?
答案 0 :(得分:0)
我在underwow文档中找不到我需要的东西,因此不得不使用它来寻求解决方案。该解决方案适用于嵌入式Web服务器,因为这正是我所追求的。我正在尝试为带有路由的Angular 2+单页应用程序执行此操作。这就是我到达的:
%module libe57format
%include "stdint.i"
%include "std_string.i"
%include "std_vector.i"
namespace std {
typedef signed char int8_t;
typedef short int int16_t;
typedef int int32_t;
typedef long int int64_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
}
//Things that do not work:
%nodefaultctor e57::Node;
%ignore e57::Node::Node();
%ignore e57::Node::destImageFile() const;
//%ignore e57::Node::parent() const;
%ignore e57::Node::operator ==(e57::Node) const;
%ignore e57::Node::__equals__(e57::Node) const;
%ignore e57::Node::operator !=(e57::Node) const;
%ignore e57::Node::__notEquals__(e57::Node) const;
%ignore e57::StructureNode::StructureNode(ImageFile);
%ignore e57::StructureNode::destImageFile() const;
%ignore e57::StructureNode::parent() const;
//%ignore e57::StructureNode::get(const ustring&) const;
//%ignore e57::StructureNode::get(int64_t) const;
%ignore e57::StructureNode::operator Node() const;
%ignore e57::VectorNode::VectorNode(ImageFile);
%ignore e57::VectorNode::VectorNode(ImageFile, bool);
%ignore e57::VectorNode::destImageFile() const;
%ignore e57::VectorNode::parent() const;
%ignore e57::VectorNode::append(Node);
%ignore e57::VectorNode::get(const ustring&) const;
//%ignore e57::VectorNode::get(int64_t) const;
%ignore e57::VectorNode::operator Node() const;
//%ignore e57::SourceDestBuffer::SourceDestBuffer;
%{
#include </usr/local/include/E57Format/E57Format.h>
%}
%template(SDBVector) std::vector<e57::SourceDestBuffer>;
%ignore e57::BlobNode;
%ignore e57::ScaledIntegerNode;
%ignore e57::CompressedVectorWriter;
%rename(__type__) e57::Node::type;
%rename(__equals__) e57::Node::operator==;
%rename(__notEquals__) e57::Node::operator!=;
%rename(__equals__) e57::ImageFile::operator==;
%rename(__notEquals__) e57::ImageFile::operator!=;
%rename(__Node__) e57::StructureNode::operator Node;
%rename(__Node__) e57::VectorNode::operator Node;
%rename(__Node__) e57::CompressedVectorNode::operator Node;
%rename(__Node__) e57::IntegerNode::operator Node;
%rename(__Node__) e57::ScaledIntegerNode::operator Node;
%rename(__Node__) e57::FloatNode::operator Node;
%rename(__Node__) e57::StringNode::operator Node;
%rename(__Node__) e57::BlobNode::operator Node;
%include </usr/local/include/E57Format/E57Format.h>
这是它的作用:
请注意第一个'MY_PREFIX_PATH'之后的下划线'_'。我想让应用程序API URL与Web路径相同,但是没有多余的逻辑,我选择了下划线。