Does anyone know how to make a cloud variable server for snap?
(with replit)
Does anyone know how to make a cloud variable server for snap?
(with replit)
const express = require('express');
const app = express();
const cors = require('cors');
app.use(cors());
const ReplitDBClient = require('replitdb-client');
const client = new ReplitDBClient();
app.use((req, res, next) => {
const chunks = [];
req.on('data', chunk => chunks.push(chunk));
req.on('end', () => {
req.body = Buffer.concat(chunks).toString();
next();
});
});
app.get('/get', async (req, res) => {
const value = await client.get(req.params.name, { raw: true });
res.send(value);
});
app.post('/set', async (req, res) => {
await client.set(req.params.name, req.body);
res.send('set');
});
app.listen(8080, () => {
console.log('Listening on port 8080');
});
Ok, whats the snap code to go with that?
(the code for sending a request to the server)
thanks
do I need to hit always on?
If you have the hacker plan, then yes.
If you don't have the hacker plan use UpTimeRobot.
ok, how do I close a topic?
Set the category to help with Snap!, select a correct answer, then switch back to advanced help
ONE THING! I dont see a GET url block
File icon > Libraries > HTTPS blocks
WHAT is a library
I updated my comment if it wasn't clear enough.
/home/runner/Snap-cloud-variables/index.js:16
const value = await client.get(req.params.name, { raw: true });
^^^^^
SyntaxError: await is only valid in async function
Fixed.
Use Snap! Build Your Own Blocks
serverside SnapCloudVars - Replit
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.