This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// middleware that ensures that cors errors are prevented | |
app.use((req, res, next) => { | |
res.header('Access-Control-Allow-Origin', '*'); // allow the access of the api, to all clients/websites asking | |
res.header('Access-Control-Allow-Headers', '*'); // which kind of header we want to accept | |
if(req.method === 'OPTIONS') { | |
res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE'); | |
return res.status(200).json({}); | |
} | |
next(); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const fs = require('fs'); | |
const url = require('url'); | |
http.createServer(function(req, res) { | |
var q = url.parse(req.url, true); | |
var filename = "." + q.pathname; | |
if(filename == "./") { | |
fs.readFile('index.html', function(err, data) { | |
res.writeHead(200, {'Content-Type': 'text/html'}); |