mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-16 21:00:14 +00:00
* es2017 by default for ort-common * add visualizer and define plugin * es2017 for ort-web. also add build target for es5 * add multiple reduced size build for ort-web * resolve comments, add e2e tests and add docs
63 lines
2.2 KiB
JavaScript
63 lines
2.2 KiB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
'use strict';
|
|
|
|
// this is a simple HTTP server that enables CORS.
|
|
// following code is based on https://developer.mozilla.org/en-US/docs/Learn/Server-side/Node_server_without_framework
|
|
|
|
const http = require('http');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const validRequests = {
|
|
// .wasm files
|
|
'/dist/ort-wasm.wasm': ['dist/ort-wasm.wasm', 'application/wasm'],
|
|
'/dist/ort-wasm-simd.wasm': ['dist/ort-wasm-simd.wasm', 'application/wasm'],
|
|
'/dist/ort-wasm-threaded.wasm': ['dist/ort-wasm-threaded.wasm', 'application/wasm'],
|
|
'/dist/ort-wasm-simd-threaded.wasm': ['dist/ort-wasm-simd-threaded.wasm', 'application/wasm'],
|
|
|
|
// proxied .wasm files:
|
|
'/test-wasm-path-override/ort-wasm.wasm': ['dist/ort-wasm.wasm', 'application/wasm'],
|
|
//'/test-wasm-path-override/renamed.wasm': ['dist/ort-wasm.wasm', 'application/wasm'],
|
|
|
|
// .js files
|
|
'/dist/ort.min.js': ['dist/ort.min.js', 'text/javascript'],
|
|
'/dist/ort.js': ['dist/ort.js', 'text/javascript'],
|
|
'/dist/ort.webgl.min.js': ['dist/ort.webgl.min.js', 'text/javascript'],
|
|
'/dist/ort.wasm.min.js': ['dist/ort.wasm.min.js', 'text/javascript'],
|
|
'/dist/ort.wasm-core.min.js': ['dist/ort.wasm-core.min.js', 'text/javascript'],
|
|
};
|
|
|
|
module.exports = function (dir) {
|
|
http.createServer(function (request, response) {
|
|
console.log('request ', request.url);
|
|
|
|
const requestData = validRequests[request.url];
|
|
if (!request) {
|
|
response.writeHead(404);
|
|
response.end('404');
|
|
} else {
|
|
const [filePath, contentType] = requestData;
|
|
fs.readFile(path.resolve(dir, filePath), function (error, content) {
|
|
if (error) {
|
|
if (error.code == 'ENOENT') {
|
|
response.writeHead(404);
|
|
response.end('404');
|
|
}
|
|
else {
|
|
response.writeHead(500);
|
|
response.end('500');
|
|
}
|
|
}
|
|
else {
|
|
response.setHeader('access-control-allow-origin', '*');
|
|
response.writeHead(200, { 'Content-Type': contentType });
|
|
response.end(content, 'utf-8');
|
|
}
|
|
});
|
|
}
|
|
|
|
}).listen(8081);
|
|
console.log('Server running at http://127.0.0.1:8081/');
|
|
};
|