added cors handling

This commit is contained in:
Martin Donnelly 2020-02-15 15:24:48 +00:00
parent fa8833bc96
commit c2bde881a8
3 changed files with 71 additions and 67 deletions

View File

@ -2,11 +2,8 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="8a985735-5aff-47ce-a55f-2957d4f9c5f9" name="Default" comment="websocket stuff">
<change afterPath="$PROJECT_DIR$/server/routes/geocode.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/newapp.js" beforeDir="false" afterPath="$PROJECT_DIR$/apiserver.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apiserver.js" beforeDir="false" afterPath="$PROJECT_DIR$/apiserver.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/body-parser/HISTORY.md" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/body-parser/HISTORY.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/body-parser/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/body-parser/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/body-parser/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/body-parser/index.js" afterDir="false" />
@ -178,7 +175,7 @@
<change beforePath="$PROJECT_DIR$/node_modules/debug/.npmignore" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/History.md" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/Makefile" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/Readme.md" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/debug/Readme.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/Readme.md" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/bower.json" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/browser.js" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/component.json" beforeDir="false" />
@ -186,11 +183,11 @@
<change beforePath="$PROJECT_DIR$/node_modules/debug/node.js" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/node_modules/ms/.npmignore" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/node_modules/ms/LICENSE" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/node_modules/ms/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/debug/node_modules/ms/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/node_modules/ms/README.md" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/node_modules/ms/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/debug/node_modules/ms/index.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/node_modules/ms/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/debug/node_modules/ms/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/debug/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/debug/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/ejs/Jakefile" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/ejs/Jakefile" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/ejs/Jakefile" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/ejs/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/ejs/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/ejs/ejs.js" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/ejs/ejs.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/ejs/ejs.min.js" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/ejs/ejs.min.js" afterDir="false" />
@ -547,7 +544,7 @@
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/fresh/package.json" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/ms/.npmignore" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/ms/LICENSE" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/ms/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/ms/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/ms/README.md" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/ms/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/ms/index.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/ms/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/ms/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/parseurl/.npmignore" beforeDir="false" />
@ -558,11 +555,6 @@
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/node_modules/parseurl/package.json" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/node_modules/serve-favicon/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/serve-favicon/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/btc.js" beforeDir="false" afterPath="$PROJECT_DIR$/server/routes/btc.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/temp.js" beforeDir="false" afterPath="$PROJECT_DIR$/server/routes/temp.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/time.js" beforeDir="false" afterPath="$PROJECT_DIR$/server/routes/time.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/trains.js" beforeDir="false" afterPath="$PROJECT_DIR$/server/routes/trains.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/weight.js" beforeDir="false" afterPath="$PROJECT_DIR$/routes/weight.js" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -579,13 +571,14 @@
<option name="RECENT_TEMPLATES">
<list>
<option value="EJS" />
<option value="CSS File" />
<option value="JavaScript File" />
<option value="CSS File" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="UPDATE_TYPE" value="MERGE" />
</component>
<component name="JsBowerSettings">
<exe-path>/usr/local/bin/bower</exe-path>
@ -649,9 +642,9 @@
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="true" />
<property name="ignore_missing_gitignore" value="true" />
<property name="javascript.nodejs.core.library.configured.version" value="10.16.2" />
<property name="javascript.nodejs.core.library.configured.version" value="12.15.0" />
<property name="js-jscs-nodeInterpreter" value="/usr/local/bin/node" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../rinser" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="list.type.of.created.stylesheet" value="CSS" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.standard" value="true" />
@ -664,24 +657,15 @@
<property name="nodejs_interpreter_path" value="node" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="restartRequiresConfirmation" value="false" />
<property name="settings.editor.selected.configurable" value="editor.preferences.completion" />
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/server/routes" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/public/lib" />
</key>
</component>
<component name="RunManager" selected="Node.js.newapp">
<configuration default="true" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application">
<method />
</configuration>
<configuration default="true" type="DartTestRunConfigurationType" factoryName="Dart Test">
<method />
</configuration>
<configuration name="newapp" type="NodeJSConfigurationType" path-to-node="$USER_HOME$/.nvm/versions/node/v10.16.2/bin/node" path-to-js-file="$PROJECT_DIR$/apiserver.js" working-dir="$PROJECT_DIR$">
<configuration name="newapp" type="NodeJSConfigurationType" path-to-node="$USER_HOME$/.nvm/versions/node/v10.16.2/bin/node" path-to-js-file="newapp.js" working-dir="$PROJECT_DIR$">
<envs>
<env name="DB_HOME" value="$USER_HOME$" />
</envs>
@ -723,9 +707,19 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1447021065296</updated>
<workItem from="1580742040516" duration="2575000" />
<workItem from="1580772170349" duration="2954000" />
<workItem from="1581512872729" duration="33000" />
<workItem from="1580742040516" duration="1072000" />
<workItem from="1581512466749" duration="1397000" />
<workItem from="1581513879643" duration="811000" />
<workItem from="1581685756510" duration="88000" />
<workItem from="1581685860748" duration="140000" />
<workItem from="1581771120795" duration="1936000" />
</task>
<task id="LOCAL-00007" summary="trying to persist the db again">
<created>1447077123179</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1447077123179</updated>
</task>
<task id="LOCAL-00008" summary="trying to persist the db again">
<created>1447756672584</created>
@ -1063,14 +1057,7 @@
<option name="project" value="LOCAL" />
<updated>1455711342213</updated>
</task>
<task id="LOCAL-00056" summary="websocket stuff">
<created>1580743625695</created>
<option name="number" value="00056" />
<option name="presentableId" value="LOCAL-00056" />
<option name="project" value="LOCAL" />
<updated>1580743625695</updated>
</task>
<option name="localTasksCounter" value="57" />
<option name="localTasksCounter" value="56" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -1119,50 +1106,63 @@
<option name="LAST_COMMIT_MESSAGE" value="websocket stuff" />
</component>
<component name="WindowStateProjectService">
<state x="2800" y="254" key="#Usage_Scope" timestamp="1580744275276">
<state x="2621" y="251" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1580742065211">
<screen x="2048" y="23" width="2048" height="1129" />
</state>
<state x="2800" y="254" key="#Usage_Scope/0.23.2048.1129/2048.23.2048.1129@2048.23.2048.1129" timestamp="1580744275276" />
<state x="573" y="251" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1580772438478">
<screen x="0" y="23" width="2048" height="1129" />
</state>
<state x="573" y="251" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.23.2048.1129/2048.23.2048.1129@0.23.2048.1129" timestamp="1580772438478" />
<state x="2621" y="251" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.23.2048.1129/2048.23.2048.1129@2048.23.2048.1129" timestamp="1580742065211" />
<state x="2938" y="375" key="#com.intellij.ide.scriptingContext.ui.PerFileMappingsDialogWrapper" timestamp="1580744307356">
<screen x="2048" y="23" width="2048" height="1129" />
<state x="1556" y="865" width="729" height="498" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1581513834745">
<screen x="0" y="50" width="3840" height="2110" />
</state>
<state x="2938" y="375" key="#com.intellij.ide.scriptingContext.ui.PerFileMappingsDialogWrapper/0.23.2048.1129/2048.23.2048.1129@2048.23.2048.1129" timestamp="1580744307356" />
<state x="2847" y="169" key="CommitChangelistDialog2" timestamp="1580743625177">
<screen x="2048" y="23" width="2048" height="1129" />
<state x="1556" y="865" width="729" height="498" key="#com.intellij.fileTypes.FileTypeChooser/0.50.3840.2110@0.50.3840.2110" timestamp="1581513834745" />
<state width="1888" height="573" key="GridCell.Tab.0.bottom" timestamp="1581513862731">
<screen x="0" y="50" width="3840" height="2110" />
</state>
<state x="2847" y="169" key="CommitChangelistDialog2/0.23.2048.1129/2048.23.2048.1129@2048.23.2048.1129" timestamp="1580743625177" />
<state width="1705" height="306" key="GridCell.Tab.0.bottom" timestamp="1580775543132">
<screen x="0" y="23" width="2048" height="1129" />
<state width="829" height="207" key="GridCell.Tab.0.bottom/0.23.2048.1129/2048.23.2048.1129@0.23.2048.1129" timestamp="1580741348535" />
<state width="1888" height="573" key="GridCell.Tab.0.bottom/0.50.3840.2110@0.50.3840.2110" timestamp="1581513862731" />
<state width="1888" height="573" key="GridCell.Tab.0.center" timestamp="1581513862731">
<screen x="0" y="50" width="3840" height="2110" />
</state>
<state width="1705" height="306" key="GridCell.Tab.0.bottom/0.23.2048.1129/2048.23.2048.1129@0.23.2048.1129" timestamp="1580775543132" />
<state width="1705" height="306" key="GridCell.Tab.0.center" timestamp="1580775543131">
<screen x="0" y="23" width="2048" height="1129" />
<state width="829" height="207" key="GridCell.Tab.0.center/0.23.2048.1129/2048.23.2048.1129@0.23.2048.1129" timestamp="1580741348534" />
<state width="1888" height="573" key="GridCell.Tab.0.center/0.50.3840.2110@0.50.3840.2110" timestamp="1581513862731" />
<state width="1888" height="573" key="GridCell.Tab.0.left" timestamp="1581513862731">
<screen x="0" y="50" width="3840" height="2110" />
</state>
<state width="1705" height="306" key="GridCell.Tab.0.center/0.23.2048.1129/2048.23.2048.1129@0.23.2048.1129" timestamp="1580775543131" />
<state width="1705" height="306" key="GridCell.Tab.0.left" timestamp="1580775543131">
<screen x="0" y="23" width="2048" height="1129" />
<state width="829" height="207" key="GridCell.Tab.0.left/0.23.2048.1129/2048.23.2048.1129@0.23.2048.1129" timestamp="1580741348533" />
<state width="1888" height="573" key="GridCell.Tab.0.left/0.50.3840.2110@0.50.3840.2110" timestamp="1581513862731" />
<state width="1888" height="573" key="GridCell.Tab.0.right" timestamp="1581513862731">
<screen x="0" y="50" width="3840" height="2110" />
</state>
<state width="1705" height="306" key="GridCell.Tab.0.left/0.23.2048.1129/2048.23.2048.1129@0.23.2048.1129" timestamp="1580775543131" />
<state width="1705" height="306" key="GridCell.Tab.0.right" timestamp="1580775543131">
<screen x="0" y="23" width="2048" height="1129" />
<state width="829" height="207" key="GridCell.Tab.0.right/0.23.2048.1129/2048.23.2048.1129@0.23.2048.1129" timestamp="1580741348534" />
<state width="1888" height="573" key="GridCell.Tab.0.right/0.50.3840.2110@0.50.3840.2110" timestamp="1581513862731" />
<state x="1428" y="619" width="986" height="990" key="MultipleFileMergeDialog" timestamp="1581513773146">
<screen x="0" y="50" width="3840" height="2110" />
</state>
<state width="1705" height="306" key="GridCell.Tab.0.right/0.23.2048.1129/2048.23.2048.1129@0.23.2048.1129" timestamp="1580775543131" />
<state x="2717" y="226" key="SettingsEditor" timestamp="1580744316951">
<screen x="2048" y="23" width="2048" height="1129" />
<state x="1428" y="619" width="986" height="990" key="MultipleFileMergeDialog/0.50.3840.2110@0.50.3840.2110" timestamp="1581513773146" />
<state x="723" y="514" width="1587" height="1274" key="SettingsEditor" timestamp="1581685921677">
<screen x="0" y="50" width="3840" height="2110" />
</state>
<state x="2717" y="226" key="SettingsEditor/0.23.2048.1129/2048.23.2048.1129@2048.23.2048.1129" timestamp="1580744316951" />
<state x="723" y="514" width="1587" height="1274" key="SettingsEditor/0.50.3840.2110@0.50.3840.2110" timestamp="1581685921677" />
<state x="3047" y="512" key="VCS.EditChangelistDialog" timestamp="1580742321561">
<screen x="2048" y="23" width="2048" height="1129" />
</state>
<state x="3047" y="512" key="VCS.EditChangelistDialog/0.23.2048.1129/2048.23.2048.1129@2048.23.2048.1129" timestamp="1580742321561" />
<state x="2756" y="329" key="Vcs.Push.Dialog.v2" timestamp="1580743628919">
<state x="2756" y="329" key="Vcs.Push.Dialog.v2" timestamp="1580742249539">
<screen x="2048" y="23" width="2048" height="1129" />
</state>
<state x="2756" y="329" key="Vcs.Push.Dialog.v2/0.23.2048.1129/2048.23.2048.1129@2048.23.2048.1129" timestamp="1580743628919" />
<state x="2756" y="329" key="Vcs.Push.Dialog.v2/0.23.2048.1129/2048.23.2048.1129@2048.23.2048.1129" timestamp="1580742249539" />
<state x="1574" y="971" width="693" height="286" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2" timestamp="1581513760314">
<screen x="0" y="50" width="3840" height="2110" />
</state>
<state x="1574" y="971" width="693" height="286" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2/0.50.3840.2110@0.50.3840.2110" timestamp="1581513760314" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="javascript">
<url>file://$PROJECT_DIR$/routes/weight.js</url>
<line>5</line>
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

View File

@ -3,6 +3,7 @@ require('dotenv').config();
const express = require('express');
const basicAuth = require('express-basic-auth');
const helmet = require('helmet');
const cors = require('cors');
const path = require('path');
const http = require('http');
@ -27,6 +28,8 @@ app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(cors());
app.use(basicAuth({
'users': {
'testmvc': '9E#!7!Nu5kd$FnCBQj_=Bh6WgGPqG@g-ETK%y3Ht+87rRT!Vvp=DH=6&w7mJ*36!',

View File

@ -8,6 +8,7 @@
"dependencies": {
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"debug": "^4.1.1",
"dotenv": "^8.2.0",
"ejs": "^2.7.1",